I am using cx4a.org's Auto Complete mode with GNU Emacs 24.3.1, and following options:
(setq ac-ignore-case nil)
(define-key ac-completing-map "\r" nil)
(setq ac-auto-start 2)
When I type a prefix at the end of a line, and wish to move down a line (pressing the Down arrow key), instead of moving the cursor, the auto-completion menu pops up. For example (in Python)
def passing():
print("passing")
def passed():
print("passed")
# insert new function here
def willpass():
print("will pass")
When I insert a dummy function (that just passes) at the comment location, after typing pass, I press the Down arrow key (wanting to move down a line), but instead, the menu pops up with options "pass, passed, passing".
How do I prevent this menu from popping up in this usage example? I tried re-mapping <up> and <down> in both ac-mode-map and ac-menu-map to nil, with no effect.
Note: Pressing C-n instead of Down does not open the menu, but it feels unnatural. And rebinding Down to (next-line) did nothing.
Also, I could sidestep this issue by setting ac-delay to 1 and setting the trigger-key to Tab, but this set of options has other drawbacks that led me to revert back to the first set of options.
Use this:
(define-key ac-completing-map [down] nil)
(define-key ac-completing-map [up] nil)
And actually most people prefer C-n to down.
Did you swap Ctrl and Caps?
Related
The issue:
I have started a Common Lisp session with a *slime-repl sbcl* in its default vertical split.
I am on a symbol, let's say cond, and press the key for slime-describe-symbol which in my case is ,hh as I am using spacemacs.
This opens a buffer *slime-description* on top of the repl window.
I am now left in a situation where I have to:
move to the split on the right
switch buffer to the slime *slime-repl sbcl*
return to my original buffer
I have to do this every time I open a help file which seems strange as the designed workflow. I would expect this to be possible using a single keystroke.
What is the intended way of managing this?
In plain emacs the keyboard shortcut for moving to the other window is 'C-x o' (other window). I'd assume the easiest way to achieve the automatic cursor movement when describing a symbol would be to define your own custom elisp function by modifying slime-describe-symbol to move the cursor to the slime-description window and (re)bind the keyboard shortcut.
On my machine:
(defun my-slime-describe-symbol (symbol-name)
"Describe the symbol at point."
(interactive (list (slime-read-symbol-name "Describe symbol: ")))
(when (not symbol-name)
(error "No symbol given"))
(slime-eval-describe `(swank:describe-symbol ,symbol-name))
(switch-to-buffer-other-window "*slime-description*"))
and then define the keyboard shortcut to your liking:
(define-key slime-mode-map (kbd "C-c C-d d") 'my-slime-describe-symbol)
(define-key slime-mode-map (kbd "C-c C-d C-d") 'my-slime-describe-symbol)
I am using python with elpy mode which work fine, however I am really annoyed by the default which runs executes the command under the cursor whenever I press CTRL+ENTER since I keep pressing it accidentally.
How do I disable this behavior? I tried
(global-set-key (kbd "<C-return>") nil)
but that does not seem to have an effect. Any help is much appreciated.
It's probably not set in the global key map, but in the major mode's map or some minor mode's map. In a buffer with the key bound, do C-h k C-<return> to see the binding; it should show the key map that it's in. Then use define-key to change it. E.g. if foo-mode-map contains the binding, do
(define-key foo-mode-map (kbd "C-<return>") nil)
You will probably want to add that code to either a hook or wrap it in with-eval-after-load, so foo-mode-map is defined when it runs.
I want Emacs to work like this:
Let auto-complete auto-popup menu:
(setq ac-auto-show-menu 0.8)
(setq ac-delay 0.1)
Use C-n/p / M-n/p to select auto-complete popup menu candidates:
(define-key ac-menu-map (kbd "M-n") 'ac-next)
(define-key ac-menu-map (kbd "M-p") 'ac-previous)
When selecting a candiate
disable TAB / S-TAB in popup menu selection:
(define-key ac-menu-map (kbd "<tab>") nil)
(define-key ac-menu-map (kbd "<S-tab>") nil)
press Enter to select the candiate, without inserting newline:
;; ???
if the candidate is an abbrev, Enter should only select the candiate:
;; ???
... and pressing Space should cause Emacs to auto-expand the abbrev.
if the candidate is a dabbrev, pressing M-\ on candidate should trigger dabbrev-expand.
pressing TAB / C-i to expand the candidate for yasnippet:
(setq yas-trigger-key "TAB")
I set this, but the trigger does not expand when I press TAB.
pressing TAB to expand a snippet trigger while in a field:
(setq yas-triggers-in-field t)
pressing C-j to jump to next field:
(setq yas-next-field-key '("<tab>")) ;; or "C-j"
How can I expand a snippet within a snippet using yasnippet?
Some explanations
There are two TABs in Emacs:
(kbd "TAB") / (\t, [9])
(kbd "<tab>") / ([tab])
If modes like yasnippet and auto-complete want to bind to TAB, their trigger key must be the same as the original tab command. Since Emacs binds indent-for-tab-command to (kbd "TAB"), it's better to use that as the trigger key. yasnippet binds to it by default, and it is easy to set up auto-complete to trigger using TAB as well:
;; trigger using TAB and disable auto-start
(custom-set-variables
'(ac-trigger-key "TAB")
'(ac-auto-start nil)
'(ac-use-menu-map t))
But in some modes (ruby-mode, markdown-mode, org-mode, etc.), the command is bound to
(kbd "<tab>"). When the real tab key is typed, the function bound to (kbd "<tab>) has higher priority, so yasnippet and auto-complete are not invoked. This is easy to fix by moving the key binding:
(defun iy-tab-noconflict ()
(let ((command (key-binding [tab]))) ; remember command
(local-unset-key [tab]) ; unset from (kbd "<tab>")
(local-set-key (kbd "TAB") command))) ; re-bind to (kbd "TAB")
(add-hook 'ruby-mode-hook 'iy-ac-tab-noconflict)
(add-hook 'markdown-mode-hook 'iy-ac-tab-noconflict)
(add-hook 'org-mode-hook 'iy-ac-tab-noconflict)
My setup
I downloaded yasnippet, auto-complete via the el-get packager manager. I'm using Ubuntu 12.04 and Emacs 24.3.50.1.
Wrapping up
I know this problem is a little long, but it really makes it difficult for me to use auto-complete and yasnippet. If the basic key binding doesn't work smoothly, this slows down my workflow quite a bit. I think many people have similar problems because I found some similar questions on the internet (though none of them are exactly like mine).
As you can see above, some of the relevant settings I already know. (But if you think I made a mistake somewhere, please tell me.) There are also some things I still don't know how to set up (???). Maybe there isn't a way to make all of these settings work together? Let me know if that is the case, and otherwise please make sure none of these setting interfere with each other.
After I get the answer to this question, I hope to write an Emacs extension to initialize all of these settings automatically.
Thanks for your help!
I faced the problem you're describing a long time ago and resolved it like this:
bind auto-complete to TAB (also C-i which is the same)
and yasnippet to C-o.
Abbrevs are on C-o as well, but I don't use them a lot.
The advantages are:
No stateful behavior results in a much more relaxed and productive editing.
You no longer think "what will TAB do in this context?" before pressing,
you just press it.
You no longer check if you got the expected outcome, because there's only one.
You can use auto-complete while in the process of expanding yasnippet.
C-i and C-o are neighbors and very easy to press.
Yasnippets now expand reliably in any mode since no mode overrides C-o.
This may be not what you want right now but consider trying it:
you might like it after a while.
Bind RET or <return> to function ac-expand. This is for select candidate.
I have a really annoying situation; when I'm editing in emacs and the auto-complete box loads up, I find I'm using the escape key to quit out of it when I don't need it. The problem is this has the unwanted behaviour of making the current window the only window. This is really annoying when I've set up a number of windows/frames for various tasks.
I'm using auto-complete.el, with the following options:
(ac-config-default)
(define-key ac-completing-map "\e" 'ac-stop) ; use esc key to exit completion
(global-set-key "\C-f" 'ac-isearch)
Since hitting the ESC key is in my muscle-memory for dismissing UI elements (drop-downs, dialogs, etc), any idea on how I can hit escape without having the current focussed frame take over?
In Mac emacs "ESC ESC ESC" is bound to keyboard-escape-quit by default, which is what you're accidentally invoking. This fixed it for me:
(global-unset-key (kbd "ESC ESC ESC"))
Press C-g instead of escape.ff
You know how when you hit the up arrow in bash it will fill in the last command you typed in? Is there any way to do this in nrepl?
So far I've been doing a reverse search (C-r), typing the first few characters of the line in question, killing the line(s) (C-k), jumping to the end of the buffer (M->) and yanking the killed line (C-y). Is there an easier way to do this?
You can use M-p and M-n to navigate up and down in the input history. Also, the current input can be used as a search pattern, i.e. type the start of the command you want to match, then M-p will take you to the next match. This uses the functions nrepl-previous-input and nrepl-next-input. If you don't like those keybindings, you can also rebind to <up> and <down>:
(define-key nrepl-mode-map (kbd "<up>") 'nrepl-previous-input)
(define-key nrepl-mode-map (kbd "<down>") 'nrepl-next-input)
Just add this to your .emacs (and evaluate C-x C-e after each line if you don't want to restart your Emacs). Also, note that M-n and M-p are likely to be bound to similar functionality in other REPL and comint like modes.
If you're using Cider, you can add the following to your user config:
(define-key cider-repl-mode-map (kbd "<up>") 'cider-repl-previous-input)
(define-key cider-repl-mode-map (kbd "<down>") 'cider-repl-next-input)
To persist the history for the next time you open a repl, you also have the following options:
(setq cider-repl-wrap-history t)
(setq cider-repl-history-size 1000)
(setq cider-repl-history-file "~/.cider-repl-history")
cider-repl-history-file is required if you want a persistent history. If you use a relative path, the history will be local to the current project.