Paredit Wrap Round command not bound to M-( - emacs

I'm using Paredit and was studying the cheatsheet. The source and documentation suggest that M-( should trigger paredit-wrap-round but on my system when I use C-h k M-( to find the keybinding for M-( I get:
M-( runs the command paredit-backward-slurp-sexp, which is an
interactive compiled Lisp function in `paredit.el'.
It is bound to <C-M-left>, C-(, ESC <C-left>, M-(.
...
How do I find out what is rebinding M-( to paredit-backward-slurp-sexp and make it back to normal?

You can use an external tool: describe-key-and-map-briefly to find out which keymap the definition is coming from, then advice around define-key to log load-file-name to show where the guilty call is coming from.
Before all that, you probably want to make sure your version of paredit isn't doing anything weird by using emacs -Q and loading just paredit and checking the bindings.

Related

Emacs Macro to Start in Shell Mode and Run a Command

I have a confession: I don't know Lisp. Despite that fact, with a bit of help from some co-workers, I managed to write an emacs macro/script which:
switched to shell mode (ie. M-x shell-mode)
disabled truncating lines (ie. M-x toggle-truncate-lines)
started a database console (ie. "mysql")
I was then able to start emacs with that macro using the --script option, and suddenly I had a way to start mysql in a much friendlier environment with a single command :-)
But here's the problem: I changed jobs and left that script behind. Now I'd very much like to re-create that script at my new job, but I no longer have any emacs experts to help me write it like I did at the old job.
Now, I really hate SO posts where someone basically says "please write my code for me", so I don't want to do that. However, if any emacs macro experts could at least give me some pointers (like "here's how you invoke a M-x command in a macro"), or point me to an emacs-macro-writing guide, or otherwise "teach me to fish" on this issue, I would greatly appreciate it.
... and if someone just happened to have a similar script already lying around that they wanted to post, I certainly wouldn't complain ;-)
Most emacs commands (i.e., M-x toggle-truncate-lines) can be translated directly to elisp by wrapping them in parentheses:
(toggle-truncate-lines)
The rumours are true, in lisp you just scatter parentheses around and they make magic.
Now in this case, you can do better. Toggling makes sense for an interactive function, but in a program you don't really want to toggle truncate-lines, you want to turn on truncate-lines. Its the same thing if truncate-lines was turned off to begin with, but you don't know when your program will be run next. Anyways, in Emacs, features are often controlled by a variable. In this case, the variable is truncate-lines, and to turn that feature on, you set the variable to t (which means true).
To do this, use:
(setq truncate-lines t)
We use setq instead of = for assignment, because they made lisp before = had been invented.
For the real scoop you should take a look at Robert Chassel's excellent "An introduction to to Programming in Emacs Lisp". It comes built-in with your emacs, you can get to it with C-h i m Emacs Lisp Intro.
A good way (I think) to start writing elisp functions is to record keyboard macros, and then to analyse them using edit-kbd-macro
For example, if you start recording a keyboard macro using f3, then do interactively all the things you want and terminate the macro using f4, you can see the underlying emacs-lisp commands using M-xedit-kbd-macrof4 (this last f4 is the key binding you'd have used to execute the keyboard macro)
<<shell>> ;; shell
<<toggle-truncate-lines>> ;; toggle-truncate-lines
mysql ;; self-insert-command * 5
RET ;; comint-send-input
Now you can write a script using these functions, looking up the documentation (e.g. C-h ftoggle-truncate-lines) to see if you should call them with special arguments in non-interactive mode.
You should also replace self-insert-command by calls to insert.
This should give you something like the following script, which you can call using emacs --load myscript.el
(shell)
(toggle-truncate-lines 1)
(insert "mysql")
(comint-send-input)
Of course, this might not work as expected the first time, so you might have to eval (setq debug-on-error t) to get debugging information.
What version of Emacs are you using?
In Emacs 24, I have M-x sql-mysql, which does everything you ask and has font-locking.

Clojure documentation in Emacs

Is it possible to view Clojure function documentation in Emacs? Namely, can I configure Emacs to lookup Clojure functions under the cursor?
I'm using clojure-mode and SLIME. Oddly, I can't even use apropos or dir in SLIME's repl, although they're automatically loaded by lein repl.
Try the function slime-describe-symbol, which is usually bound to C-c C-d d.
Place the point somewhere near the function name and hit C-c, then C-d, and then d.
There's also slime-describe-function, bound to C-c C-d f, but I rarely use it, as it's less general than the aforementioned symbol-related lookup function.
To see all the documentation-related functions, press C-c C-d C-h. These bindings are not specific to Clojure; they are instead defined by SLIME, and will work as well if not better for other Lisp dialects.
I find the combination of slime-apropos and eldoc minor mode (make sure you have swank-clojure 1.4.0 as it fixes both of those) better than the slime-describe-symbol/function commands mentioned above.
From SLIME REPL you can run (use 'clojure.repl). This will make functions like apropos and doc available

A few Emacs noob questions

Sorry if these are obvious answers but I've googled around and can't seem to find what I'm looking for.
When I have multiple files open in split screen mode using C-x C-3 how do I close JUST the window I'm currently in and no other?
I'm using Ruby and it doesn't seem to auto indent my def end correctly.. is there a Ruby plugin that will fix this?
Is there a command to go to a specific line?
How do I interpret ruby from within emacs?
1. When I have multiple files open in split screen mode using C-x C-3 how do I close JUST the window I'm currently in and no other?
To close current view C-x 0. (Btw, I think you're referring to C-x 3.)
2. I'm using Ruby and it doesn't seem to auto indent my def end correctly.. is there a Ruby plugin that will fix this?
Have a look at
ruby-mode for emacs
RubyMode
3. Is there a command to go to a specific line?
Sure, M-g g (or M-x goto-line)
4. How do I interpret ruby from within emacs?
Don't know. You could try rubydebug.
You can also see C-h b which will give you key binding for the current-buffer to give you a lot of additional things that you might need. Once you install any Ruby Mode, you can also use C-h m to see key binding for that specific modes in your current buffer, including ruby mode.
for Q3) in addition you might want to know
C-h w COMMAND
will always show you the key binding for a funcion
C-h w goto-line RET
goto-line is on M-g g, M-g M-g, <menu-bar> <edit> <goto> <go-to-line>
for Q4) you could start a shell in a buffer, either M-x eshell or M-x shell and the simply run your script there.
Using the eshell configuration in [1] you can easily switch between the shell and your script source (pressing C-z).
[1] http://www.emacswiki.org/alex/2008-08-19_Emacs_on_Windows

Emacs define-key, Viper-mode key binding

I'm trying to learn emacs, getting vi custom key bindings.
Using Viper-mode, what is the correct way to re-bind a key? (I'm using Colemak keyboard layout(instead of qwerty) so have to change things like n->j) But would like it to work in viper-mode.
From this key binding guide on GNU.org:
http://www.gnu.org/software/emacs/manual/html_node/viper/Key-Bindings.html
It says the command to put in your .viper file is:
(define-key viper-vi-global-user-map "\C-v" 'scroll-down)
It doesn't work for me... in fact not sure I even have the function "define-key"...
M-x define-key [No match]
I'm not sure if 'define-key' is available on my version of emacs?
This works, but not in viper-mode
(global-set-key "n" "j")
Any help would be much appreciated. This is my first day using Emacs, to it's a pain getting Colemak & Viper-mode to work properly.
Thank for any help...
Hopefully some useful answers here:
First, having that line in the .viper works for me. Note that the viper-vi-global-user-map applies when you're in command mode, not insert mode.
Secondly, define-key isn't a command, it's a regular function, which just means that it cannot be called using M-x. See this Emacs wiki page for a little more detail on that distinction. But that was a good attempt.
Third, the global-set-key is a command, you could have tried making a change using M-x global-set-key. But, that sets the key in the current global map, which isn't the same as viper-vi-global-user-map. Viper-mode uses a bunch of different keymaps to make Emacs behave like vi, but all of the maps are overlaid on top of the global map.
I'm guessing that you found that C-v wasn't bound like you want when you're in insert mode. And that can be solved by adding this to your .viper:
(define-key viper-insert-global-user-map "\C-v" 'scroll-down)
Lastly, scroll-down may not be what you want. The down refers to the text moving down (given the perspective of a fixed window). C-v is generally bound to 'scroll-up. But,maybe it is exactly what you want.
Caveat: I'm not a viper-mode user, I don't even know how to use vi. So my terminology may be off. But I find the challenge of changing things in viper-mode very interesting.
Edited to add
From your comment it sounds like you want n to be the same as what j is bound to by default. Try adding this:
(define-key viper-vi-global-user-map "n" 'viper-next-line)
In "normal" mode I did M-x describe-key j, which told me that j is bound to 'viper-next-line, and the above line will bind n to the same routine. Repeat for the rest of the bindings you want to shift around.
in modern times evil-mode is the vim emulation layer for emacs, and to tweak it for colemak, my https://github.com/wbolster/evil-colemak-basics package helps a lot.

What are the good things about slime?

As I asked here, I couldn't make it run Aquamacs/slime/clojure, but I could use Auqamacs/clojure with 'M-x conjure-mode', then C-c C-z (run clojure) and C-c C-e (run expression).
I don't have an experience with SLIME, but I feel that C-c C-z and C-c C-e is just enough for lisp/conjure REPL or debugging.
What features SLIME has more than these features? What people use SLIME for?
So, so, so much more.
M-. to go to a definition.
C-c C-k to compile the current buffer.
M-p & M-n to go forwards and backward in REPL history.
M-<tab> for completion.
A debugger. A wonderful REPL.
And so much more.
Slime gives so much: look at its manual.
It shouldn't be too hard to set up: this post is a great starting point.
Tab completion of java class members in addition to clojure functions and such.
Apart from what had already been said:
Highlighting errors, warnings and notes in source code buffers.
Inspector. An object viewer.
Paredit. Paredit adds comfort and ease to editing lisp code.
Macroexpansion.