This is my ~/.emacs file:
(setq-default c-basic-offset 4 c-default-style "linux")
(setq-default tab-width 4 indent-tabs-mode t)
(define-key c-mode-base-map (kbd "RET") 'newline-and-indent)
I'm getting a warning when I open up emacs:
Warning (initialization): An error occurred while loading
c:/home/.emacs:
Symbol's value as variable is void: c-mode-base-map
To ensure normal operations, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with the
--debug-init option to view a complete error backtrace.
I ran --debug-init and this is what it returned. I don't know what I means:
Debugger entered--Lisp error: (void-variable c-mode-base-map)
(define-key c-mode-base-map (kbd "RET") (quote newline-and-indent))
eval-buffer(#<buffer *load*> nil "c:/home/.emacs" nil t)
; Reading at buffer position 311
load-with-code-conversion("c:/home/.emacs" "c:/home/.emacs" t t)
load("~/.emacs" t t)
What this means is that, at the point at which you invoke define-key, c-mode-base-map is not yet defined by anything.
The usual fix is to find out where this is defined and require that module. In this case:
(require 'cc-mode)
However there are other possible fixes as well, for example setting the key-binding in a mode hook, or using eval-after-load. Which one you use is up to you; I tend to do the KISS approach since I don't generally care about startup time; but if you do you may want something lazier.
This is my ~/.emacs file:
(setq-default c-basic-offset 4 c-default-style "linux")
(setq-default tab-width 4 indent-tabs-mode t)
(define-key c-mode-base-map (kbd "RET") 'newline-and-indent)
I'm getting a warning when I open up emacs:
Warning (initialization): An error occurred while loading
c:/home/.emacs:
Symbol's value as variable is void: c-mode-base-map
To ensure normal operations, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with the
--debug-init option to view a complete error backtrace.
I ran --debug-init and this is what it returned. I don't know what I means:
Debugger entered--Lisp error: (void-variable c-mode-base-map)
(define-key c-mode-base-map (kbd "RET") (quote newline-and-indent))
eval-buffer(#<buffer *load*> nil "c:/home/.emacs" nil t)
; Reading at buffer position 311
load-with-code-conversion("c:/home/.emacs" "c:/home/.emacs" t t)
load("~/.emacs" t t)
What this means is that, at the point at which you invoke define-key, c-mode-base-map is not yet defined by anything.
The usual fix is to find out where this is defined and require that module. In this case:
(require 'cc-mode)
However there are other possible fixes as well, for example setting the key-binding in a mode hook, or using eval-after-load. Which one you use is up to you; I tend to do the KISS approach since I don't generally care about startup time; but if you do you may want something lazier.
(dolist (abcc '("C-a" "C-b"))
(global-unset-key (kbd abcc)))
It keeps on giving the error :
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p abcc)
read-kbd-macro(abcc)
#[(keys) "\301!\207" [keys read-kbd-macro] 2 2180088](abcc)
(kbd abcc)
(global-unset-key (kbd abcc))
(while --dolist-tail-- (setq abcc (car --dolist-tail--)) (global-unset-key (kbd abcc)) (setq --dolist-tail-- (cdr --dolist-tail--)))
(let ((--dolist-tail-- ...) abcc) (while --dolist-tail-- (setq abcc ...) (global-unset-key ...) (setq --dolist-tail-- ...)))
(dolist (abcc (quote ...)) (global-unset-key (kbd abcc)))
eval-buffer(#<buffer *load*> nil "/home/name/.emacs" nil t) ; Reading at buffer position 63
load-with-code-conversion("/home/name/.emacs" "/home/name/.emacs" t t)
load("~/.emacs" t t)
#[nil "\205\264
I initially thought that this is a bug in Emacs. I was very surprised nobody's come across this before.
Here is a workaround you can use:
(dolist (abcc '("C-a" "C-b"))
(global-unset-key (read-kbd-macro abcc)))
What happens is kbd is a macro that wraps a function, however it doesn't evaluate its parameter explicitly. So the symbol abcc is getting passed straight to the function.
After a bit more thinking (and reading the docs). It's actually user error.
The doc-string for kbd clearly states that it should be used on string constants.
So kbd should be used when you only want a key's internal representation to appear in the compiled byte-code. e.g.
(define-key foo-mode-map (kbd "C-a") 'foo)
But read-kbd-macro should be used when you want the argument to be evaluated.
(keys) is a macro that just passes right through to (read-kbd-macro). The former also errors out for me for some reason, but the latter doesn't. Try that instead?
kbd is a macro, so it does not evaluate its arg.
I just installed Devel::PerlySense 0.0180.
I have put the following in my .emacs file:
; PerlySense
(load "~/perly-sense")
(global-unset-key "\C-p")
(global-set-key (kbd "\C-p \C-d") 'perly-sense-smart-docs-at-point)
(global-set-key (kbd "\C-p \C-g") 'perly-sense-smart-go-to-at-point)
But, now whenever I try to load a Perl file in emacs, I get the following error prior to it getting loaded:
error "Key sequence C-p m f starts
with non-prefix key C-p"
How can I fixed this? I'm new to emacs, so would really appreciate any help in this regard.
Update:
The link submitted by ysth suggests, doing the following :
(use-local-map (make-sparse-keymap))
=> nil
(local-set-key "\C-p" ctl-x-map)
=> nil
(key-binding "\C-p\C-f")
=> find-file
(key-binding "\C-p6")
=> nil
Now, do i need to add this to my .emacs file to create the keymap?
When i add the above code to .emacs and start emacs the error i get is :
void-variable =>
What can be the problem here ?
The explicit answer to your question is this:
(define-prefix-command 'perly-sense-map)
(global-set-key (kbd "C-p") 'perly-sense-map)
(define-key perly-sense-map (kbd "C-d") 'perly-sense-smart-docs-at-point)
(define-key perly-sense-map (kbd "C-g") 'perly-sense-smart-go-to-at-point)
For more information as to what's being done, check out documentation for
define-prefix-command
keymaps
kbd
In the original post, you mixed using kbd and the older "\C-p" notation. You can read this large tutorial discussing keybindings, which has tons of information (more than what you probably need). I find the kbd usage to be the easiest, you just pass it the string that you'd see when you do help on a key (C-h k).
Emacs, by default, only allows certain keys to be prefixes (the start of multi-key commands). See http://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html
You need to create a keymap and bind it to C-p.
In Emacs, C-x o takes me to the next window.
What keyboard macro takes me to the previous window in Emacs?
You might also want to try using windmove which lets you navigate to the window of your choice based on geometry. I have the following in my .emacs file to change windows using C-x arrow-key.
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
That'd be C-- C-x o
In other words, C-x o with an argument of -1. You can specify how many windows to move by inserting a numeric argument between C-u and the command, as in C-u 2 C-x o. (C-- is a shortcut for C-u - 1)
Personally I prefer to use window-number.el
To select a different window, use Ctrl-x, Ctrl-j n
Where n is the number of the window, the modeline of each window shows it's number, as shown in the screenshot.
Just download window-number.el, place it in your emacs load-path and use the following in your .emacs
(autoload 'window-number-mode "window-number"
"A global minor mode that enables selection of windows according to
numbers with the C-x C-j prefix. Another mode,
`window-number-meta-mode' enables the use of the M- prefix."
t)
There's another similar mode called switch-window.el which gives you big numbers in the windows... (pressing the number switches the window and reverts the display.)
(source: tapoueh.org)
If you work with multiple emacs windows (>3) a lot and you will want to save some keystrokes add this to your init file and you'll be better off:
(defun frame-bck()
(interactive)
(other-window-or-frame -1)
)
(define-key (current-global-map) (kbd "M-o") 'other-window-or-frame)
(define-key (current-global-map) (kbd "M-O") 'frame-bck)
Now just cycle quickly thru the windows with M-o
There are some very good and complete answers here, but to answer the question in a minimalist fashion:
(defun prev-window ()
(interactive)
(other-window -1))
(define-key global-map (kbd "C-x p") 'prev-window)
Base on idea from #Nate but slightly modified to support backwards cycling between windows
;; Windows Cycling
(defun windmove-up-cycle()
(interactive)
(condition-case nil (windmove-up)
(error (condition-case nil (windmove-down)
(error (condition-case nil (windmove-right) (error (condition-case nil (windmove-left) (error (windmove-up))))))))))
(defun windmove-down-cycle()
(interactive)
(condition-case nil (windmove-down)
(error (condition-case nil (windmove-up)
(error (condition-case nil (windmove-left) (error (condition-case nil (windmove-right) (error (windmove-down))))))))))
(defun windmove-right-cycle()
(interactive)
(condition-case nil (windmove-right)
(error (condition-case nil (windmove-left)
(error (condition-case nil (windmove-up) (error (condition-case nil (windmove-down) (error (windmove-right))))))))))
(defun windmove-left-cycle()
(interactive)
(condition-case nil (windmove-left)
(error (condition-case nil (windmove-right)
(error (condition-case nil (windmove-down) (error (condition-case nil (windmove-up) (error (windmove-left))))))))))
(global-set-key (kbd "C-x <up>") 'windmove-up-cycle)
(global-set-key (kbd "C-x <down>") 'windmove-down-cycle)
(global-set-key (kbd "C-x <right>") 'windmove-right-cycle)
(global-set-key (kbd "C-x <left>") 'windmove-left-cycle)
Just to add to #Nate, #aspirin and #Troydm's answer I find this to be a very helpful addition if you decide to bind the windmove commands to whatever key combination you choose:
(setq windmove-wrap-around t)
With the default configuration you will get an error when you get to attempt to move to a window that doesn't exist which becomes kind of annoying after a while. However when windmove-wrap-around is set then attempting to move off the bottom of the frame for example will instead select the topmost window in the frame. This may be a more intuitive behaviour for you.
M-n and M-p makes the most sense to me, since they are analogous to C-n (next-line) and C-p (previous-line):
(define-key global-map (kbd "M-p") 'previous-multiframe-window)
(define-key global-map (kbd "M-n") 'other-window)
(inspired by to this and that)
In reference to Nate's answer, I replaced the arrow keys to use the traditional p for going up, n for going down, f for going right and b for going left. I also replaced the Ctrl with Super key as C-p, C-n, C-f and C-b are the default movement keys. This combination with M lets you jump characters and lines instead of going through just one by one after each keystroke. Thus Super key felt the best choice to keep it an easy key binding. Also, now you don't have to take your hand off the home row any more!
(global-set-key (kbd "s-p") `windmove-up)
(global-set-key (kbd "s-n") `windmove-down)
(global-set-key (kbd "s-f") `windmove-right)
(global-set-key (kbd "s-b") `windmove-left)
Hope it helps!
(global-unset-key (kbd "M-j"))
(global-unset-key (kbd "M-k"))
(global-set-key (kbd "M-j") (lambda () (interactive) (other-window 1)))
(global-set-key (kbd "M-k") (lambda () (interactive) (other-window -1)))
altj and altk will cycle through your visibles buffers. Forwards and backwards, to be exact.
There is already a package that lets you switch windows by using M-. check this website. Add this to your init file:
(require 'windmove)
(windmove-default-keybindings 'meta) ;; or use 'super to use windows key instead alt
(global-set-key (kbd "C-x a") 'ace-swap-window)
(global-set-key (kbd "C-x q") 'ace-select-window)
download ace-window from the melpa repo if you don't know how to do that
put this in your .emacs file if you don't have one create it
(package-initialize)
(require 'package)
(add-to-list 'package-archives '("melpa" , "http://melpa.org/packages/"))
(package-initialize)
then "m-x list-packages"
The fastest method I have found for switching to the previous window is to mash a couple keys together as a "key-chord". The following lets you use your left pinky+ring fingers together to go to previous window:
(key-chord-define-global "qw" 'prev-window)
(key-chord-define-global "'y" 'other-window) ; bonus for my colemak, adjust otherwise
(key-chord-define-global ";'" 'other-window) ; probably normal
(This is possible because Emacs key chords are order independent, meaning that qw is the same as wq.)