I updated my iMac desktop from Snow Leopard to Lion. I use an extended USB keyboard which has two delete keys: one together with the usual keys (above \) and one in the extended part (below fn).
In my Emacs under Snow, the first delete key worked as "backward delete" and the second one as "forward delete". However under Lion, they are both "backward delete". On the other hand, they work as expected in other contexts (TextEditor, MS Word, Terminal, this text, etc).
I presume I have to insert some additional key configuration in my .emacs file, but I don't know what. Any hints?
My Emacs is Emacs 23.3.1 (x86_64-apple-darwin, NS apple-appkit-1038.35).
Put this in your Emacs init file:
(global-set-key '[(kp-delete)] 'delete-char)
You might also need to add the following:
(global-set-key '[(delete)] 'delete-char)
(global-set-key '[(meta delete)] 'kill-word)
(global-set-key '[(meta kp-delete)] 'kill-word)
(global-set-key '[(control delete)] 'kill-word)
(global-set-key '[(control kp-delete)] 'kill-word)
Try M-x global-set-key RET key forward-delete -- if it works, try M-x repeat-complex-command but instead of reissuing the command, copy and paste it into your .emacs file.
Related
I'm using Emacs in Mac OS X terminal, installed with homebrew.
My CTRL key is my C key, and the ALT key is Meta.
How would I define key-bindings for CMD key combinations?
For instance, I want to set CMD-(right arrow) to go to the end of the line.
EDIT
I've tried #nickcarlo's suggestions below
(setq mac-command-modifier 'super)
(global-set-key (kbd "s-<right>") 'move-end-of-line)
I don't think CMD key is being set to super properly, since I don't see s-foo in the mini-buffer as I would if I had typed C-x or M-x or anything. I noticed that CMD-right, when I have two terminal windows open, switches between the two terminal windows, so I thought that might be blocking any custom setting. However, I tried:
(global-set-key (kbd "s-9") 'move-end-of-line)
.. and CMD-9 still does nothing, except beep to tell me I've pressed something wrong.
Setting non-CMD key-combos seems to work fine, like:
(global-set-key (kbd "C-w") 'move-end-of-line)
You can set it with something like:
(global-set-key (kbd "s-<right>") 'move-end-of-line)
"s" being the reference to your command key.
PS: I'm not on my mac right now so I'm not sure what exactly you need to write to set it to the specific keys you mentioned to move it to the end of line but command is represented by an s in emacs.
EDIT
Just tested this on my mac. This is the exact code you'd write (if you wanted to set it globally) to bind your command key + right arrow key to move your cursor to the end of line.
If the above doesn't work, you could also try
(global-set-key (kbd "\s <right>") 'move-end-of-line)
The difference between the one above and this one is that the above equates to CMD+right and this one equates to CMD and then release CMD and hit the right key. Both work on OS X on my system.
Also check out the following post to set your CMD as the super key in case your Emacs doesn't already register it as such:
http://ergoemacs.org/emacs/emacs_hyper_super_keys.html
Specifically, you can use the following code to set up your CMD key as Super:
(setq mac-command-modifier 'super)
In Aquamacs, what worked for me is the following
(global-set-key (kbd "A-r") 'my-command)
Step 1: c-x c-f .emacs // opens .emacs file
Step 2: Add the following lines at the end of .emacs file
;; changing the command to control
(setq mac-command-modifier 'control)
Step 3: Save .emacs file
Step 4: M-x eval-buffer //M-x = Alt-x // This evaluates .emacs buffer and reloads Emacs
Step 5: Try CMD-e to go to end of the line. // Now CMD acts like control
Step 6: Still CMD-e does't work restart Emacs.
Enjoy Using Emacs!
I'm quite new to Emacs on my Mac and I have trouble entering signs like: []|{}# etc. Instead the minibuffer shows M-5, M-6 or jumps a word forward (M-l).
I think I got my Emacs here: http://emacsformacosx.com/
and I did install this starter kit: http://kieranhealy.org/emacs-starter-kit.html
(but I hat this problem before)
I know this answer: Unable to type braces and square braces in emacs
but I couldn't get it to work yet.
I use the following -- it will place the Emacs meta key on the Mac CMD key, and free up the ALT key for normal Mac use:
(if (boundp 'ns-command-modifier)
(setq ns-command-modifier 'meta))
(if (boundp 'ns-option-modifier)
(setq ns-option-modifier nil))
I'm running emacs from within a terminal window on Mac OS X. From the bash shell at the same terminal, I can use Shift + <Home> and Shift + <end> to go to the beginning and end of the line respectively. When I'm inside emacs, these don't work. I get the error:
M-[ h is undefined
and
M-[ f is undefined
Is this the fault of emacs or the terminal emulator? I can see how to change the control characters that the terminal sends, but as far as I can tell these are the right control characters to send (and it works outside of emacs).
Put these in your .emacs:
(global-set-key (kbd "M-[ h") 'beginning-of-line)
(global-set-key (kbd "M-[ f") 'end-of-line)
I'm pretty sure it's a problem with Terminal.app as I've got some similar problems with it. I don't know how to fix it, but for your particular problem, you can use C-a and C-e to go to the beginning and end of line, respectively.
How can I define an aquamacs keyboard shortcut using the mac command key. I'd like 'command'-k to act like ctrl-k (kill line).
Thanks in advance!
Put this in your .emacs file:
(global-set-key (kbd "A-k") 'kill-line)
Then you can either press C-x C-e with the pointer at the end of this line to make the command active, or you can save the file and re-start emacs.
I have configured my emacs to run zsh shell within ansi-term. However, copy/paste no longer works i.e. nothing is getting pasted from kill-ring to the terminal.
Changing the TERM to vt100, or eterm doesn't solve the problem.
Would appreciate any ideas or solution.
To provide context I have configured ansi-term as follows:
(global-set-key "\C-x\C-a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))
(global-set-key "\C-x\ a" '(lambda ()(interactive)(ansi-term "/bin/zsh")))
You may want to simply switch between character mode and line mode while using the terminal. C-c C-j will run term-line-mode, which treats the terminal buffer more like a normal text-buffer in which you can move the cursor and yank text. You can switch back to character mode by running term-char-mode with C-c C-k.
As described in this lovely blog snippet, there's a function, term-paste, in term.el, that does exactly what you want. By default it's bound only to S-insert but the blog's recommended C-c C-y seems like a good suggestion.
ansi-term, in char-mode, takes the ordinary bindings for the terminal emulation. You need a new binding, plus a way to output to ansi-term correctly. I use this:
(defun ash-term-hooks ()
;; dabbrev-expand in term
(define-key term-raw-escape-map "/"
(lambda ()
(interactive)
(let ((beg (point)))
(dabbrev-expand nil)
(kill-region beg (point)))
(term-send-raw-string (substring-no-properties (current-kill 0)))))
;; yank in term (bound to C-c C-y)
(define-key term-raw-escape-map "\C-y"
(lambda ()
(interactive)
(term-send-raw-string (current-kill 0)))))
(add-hook 'term-mode-hook 'ash-term-hooks)
When you do this, C-c C-y will yank. It only does one yank, though, and you can't cycle through your kill-buffer. It's possible to do this, but I haven't implemented it yet.
The above solutions work well for copying text from some buffer to ansi-term, but they aren't able to copy text from ansi-term to another buffer (eg copy a command you just ran to a shell script you're editing). Adding this to my .emacs file solved that problem for me (in Emacs 24.4):
(defun my-term-mode-hook ()
(define-key term-raw-map (kbd "C-y") 'term-paste)
(define-key term-raw-map (kbd "C-k")
(lambda ()
(interactive)
(term-send-raw-string "\C-k")
(kill-line))))
(add-hook 'term-mode-hook 'my-term-mode-hook)
Note that if you want to bind kill/yank to a keystroke that starts with the ansi-term escape characters (by default C-c and C-x), and want this to work in the unlikely event that those change, you can instead define your keystrokes (without the leading escape) to term-raw-escape-map, as is done in user347585's answer.
These other solutions don't work well for me, switching between character mode and line mode causes ansi-term to stop working properly randomly, and setting ansi-term's term-paste to C-c C-y (based on Glyph's link), didn't work the code snippet was for term, not ansi-term:
(eval-after-load "ansi-term"
'(define-key ansi-term-raw-map (kbd "C-c C-y") 'term-paste))
I enabled xterm-mouse-mode, after that I was able to select text using mouse and copy using standard Mac command C button in ansi-term in emacs GUI in Mac OS X,