I want to change the key binding M-x slime-fuzzy-complete-symbol to M-TAB in both slime-mode and slime-repl.
I looked up the common lisp manual, and tried the following sentences:
(eval-after-load 'slime
`(define-key slime-prefix-map (kbd "M-TAB") 'slime-fuzzy-complete-symbol))
(add-hook 'slime-load-hook
#'(lambda ()
(define-key slime-prefix-map (kbd "M-TAB") 'slime-fuzzy-complete-symbol)))
(define-key slime-repl-mode-map (kbd "M-TAB")
'slime-fuzzy-complete-symbol)
None of them is useful. The third sentence even have an error:
Symbol's value as variable is void: slime-repl-mode-map
For reference, the following the is my init.el relate to slime:
(let ((default-directory "/usr/local/share/emacs/site-lisp/"))
(normal-top-level-add-subdirs-to-load-path))
;; Setup load-path, autoloads and your lisp system
;; Not needed if you install SLIME via MELPA
(add-to-list 'load-path "~/default-directory/slime")
(require 'slime-autoloads)
(setq inferior-lisp-program "/usr/local/opt/clozure-cl/bin/ccl64")
;; Setup slime-repl
(setq slime-contribs '(slime-scratch slime-editing-commands))
;;(setq slime-contribs '(slime-repl)) ; repl only
(setq slime-contribs '(slime-fancy)) ; almost everything
;;Setup suto-complete
(add-to-list 'load-path "~/default-directory/auto-complete/")
(require 'auto-complete-config)
;;(add-to-list 'ac-dictionary-directories "~/default-directory/auto-complete/ac-dict")
(ac-config-default)
I know this is an old question, but a few weeks ago I was looking for an answer to a similar one and I hope additional info may be useful for someone...
Here's what I've found out:
using (eval-after-load 'slime) in your .emacs (dot-emacs) file is not a good idea until you have (autoload 'slime) in it - and this is OK - without that (eval-after-load "...") may wait till the end of time for loading slime
the previous answer is OK if global-key-binding is appropriate for you
if you require or prefere local binding you may define your own function and bind it locally, e.g.:
(defun my-slime-mode-keybindings ()
"For use in `slime-mode-hook' and 'slime-repl-mode-hook."
(local-set-key (kbd "<C-f1>") 'slime-describe-symbol)
(local-set-key (kbd "<M-f1>") 'slime-apropos-all)
(local-set-key (kbd "C-c C-p") nil) ;; when you want to remove a key/sequence
(local-set-key (kbd "C-<tab>") 'ace-window)
(local-set-key (kbd "M-<tab>") 'slime-fuzzy-complete-symbol) ;; your case :)
) ;; end of defun my-slime-mode-keybindings()
;; tell emacs to use your function only in required mode(s)
(add-hook 'slime-mode-hook #'my-slime-mode-keybindings)
(add-hook 'slime-repl-mode-hook #'my-slime-mode-keybindings)
best regards
It will be better to follow the emacs documentation for this case:
Key binding commands
In your case with a global key bindoing should work:
(global-set-key (kbd "M-TAB") 'slime-fuzzy-complete-symbol)
Related
I am trying to set up my .emacs to use relative line numbering, and so I have included:
(setq display-line-numbers 'relative)
to my .emacs, however this is being ignored on load. Line numbers appear, however they are simply absolute line numbers, as opposed to relative.
Interestingly, when I run M-x load-file .emacs, it actually evaluates this line (as well as the rest of the file) and the line numbers become relative, however this doesn't happen the first time.
Below is my entire .emacs, and the line in question is on line 95/96:
(package-initialize)
(load "~/.emacs.rc/rc.el")
(load "~/.emacs.rc/misc-rc.el")
(defun rc/get-default-font ()
(cond
((eq system-type 'windows-nt) "Consolas-13")
((eq system-type 'gnu/linux) "Iosevka-24")))
(add-to-list 'default-frame-alist `(font . ,(rc/get-default-font)))
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(column-number-mode 1)
(show-paren-mode 1)
(rc/require-theme 'gruber-darker)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(svelte-mode tramp-mode elixir-mode evil move-text nasm-mode company yasnippet multiple-cursors magit haskell-mode ido-completing-read+ smex gruber-darker-theme dash-functional dash)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(eval-after-load 'zenburn
(set-face-attribute 'line-number nil :inherit 'default))
(rc/require 'smex 'ido-completing-read+)
(require 'ido-completing-read+)
(ido-mode 1)
(ido-everywhere 1)
(ido-ubiquitous-mode 1)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;;; C mode
(setq-default c-basic-offset 4
c-default-style '((java-mode . "java")
(awk-mode . "awk")
(other . "bsd")))
(add-hook 'c-mode-hook (lambda ()
(interactive)
(c-toggle-comment-style -1)))
;;; Elisp
(add-hook 'emacs-lisp-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-j")
(quote eval-print-last-sexp))))
(add-to-list 'auto-mode-alist '("Cask" . emacs-lisp-mode))
;;; Haskell mode
(rc/require 'haskell-mode)
(setq haskell-process-type 'cabal-new-repl)
(setq haskell-process-log t)
(add-hook 'haskell-mode-hook 'haskell-ident-mode)
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(add-hook 'haskell-mode-hook 'haskell-doc-mode)
(add-hook 'haskell-mode-hook 'hindent-mode)
;;; Whitespace mode
(defun rc/set-up-whitespace-handling ()
(interactive)
(whitespace-mode 1)
(add-to-list 'write-file-fucntions 'delete-trailing-whitespace))
(add-hook 'c++-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'java-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'emacs-lisp-mode 'rc/set-up-whitespace-handling)
(add-hook 'rust-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'haskell-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'python-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'erlang-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'asm-mode-hook 'rc/set-up-whitespace-handling)
(add-hook 'nasm-mode-hook 'rc/set-up-whitespace-handling)
(global-display-line-numbers-mode)
(setq display-line-numbers 'relative)
;;; Magit
(rc/require 'cl-lib)
(rc/require 'magit)
(setq magit-auto-revert-mode nil)
(global-set-key (kbd "C-c m s") 'magit-status)
(global-set-key (kbd "C-c m l") 'magit-log)
;;; Multiple Cursors
(rc/require 'multiple-cursors)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
(global-set-key (kbd "C-\"") 'mc/skip-to-next-like-this)
(global-set-key (kbd "C-:") 'mc/skip-to-previous-like-this)
;;; Dired
(require 'dired-x)
(setq dired-omit-files
(concat dired-omit-files "\\|^\\..+$"))
(setq-default dired-dwim-target t)
(setq dired-listing-switches "-alh")
;;; Yasnippet
(rc/require 'yasnippet)
(require 'yasnippet)
(setq yas/triggers-in-field nil)
(setq yas-snipped-dirs '("~/.emacs.snippets/"))
(yas-global-mode 1)
;;; Word-Wrap
(defun rc/enable-word-wrap ()
(interactive)
(toggle-word-wrap 1))
(add-hook 'markdown-mode-hook 'rc/enable-word-wrap)
;;; Company Mode
(rc/require 'company)
(require 'company)
(global-company-mode)
;;; NASM mode
(rc/require 'nasm-mode)
(add-to-list 'auto-mode-alist '("\\.asm\\'" . nasm-mode))
;;; TeX mode
(add-hook 'tex-mode-hook
(lambda ()
(interactive)
(add-to-list 'tex-verbatim-environments "code")))
;;; Move Text
(rc/require 'move-text)
(global-set-key (kbd "M-p") 'move-text-up)
(global-set-key (kbd "M-n") 'move-text-down)
(rc/require
'rust-mode
'markdown-mode
'elixir-mode
'svelte-mode
)
;;; Svelte Mode
(add-to-list 'auto-mode-alist '("\\.svelte\\'" . svelte-mode))
;;; Kill all buffers
(defun kill-all-buffers ()
(interactive)
(dolist (cur (buffer-list))
(kill-buffer cur)))
(defun close-current-buffer ()
(interactive)
(kill-buffer (buffer-name)))
(global-set-key (kbd "C-x K") 'kill-all-buffers)
(global-set-key (kbd "C-S-w") 'close-current-buffer)
(defun indent-whole-file ()
(interactive)
(indent-region (point-min) (point-max)))
(global-set-key (kbd "C-<tab>") 'indent-whole-file)
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
Did you read this part of the doc for display-line-numbers:
This variable automatically becomes buffer-local when set outside Custom.
However, setting it through Custom sets the default value.
You're using setq with a user option - not a great idea in general. Use M-x customize-option instead, or use function customize-set-variable or custom-set-variables.
Unless you do some tricky finagling, you can't depend on your setq being evaluated in any particular buffer. And anyway, you apparently want to set the default value of the option. setq-default sets the default value of a variable. But anyway, use one of the custom* functions or (even better), M-x customize-option.
You need to use display-line-numbers-type instead as per the documentation
"The command M-x display-line-numbers-mode provides a convenient way to turn on display of line numbers. This mode has a globalized variant, global-display-line-numbers-mode. The user option display-line-numbers-type controls which sub-mode of line-number display, described above, these modes will activate."
So following works.
(global-display-line-numbers-mode 1)
(setq display-line-numbers-type 'relative)
What is the proper way to override a keybinding for a major mode so it only affects the buffer-local keymap? I thought I could use local-set-key or make-local-variable, but my attempts there affect the keymaps globally (shown below).
Is it necessary to copy the map, as done below, or create a minor mode with a different keymap? It would be nice to be able to make it a local variable if possible.
For example, say I want to have original bound to C-c C-c in the global emacs-lisp-mode-map but after calling jump-to-other-buffer I want C-c C-c to be bound to local-version only in that buffer.
(defun original ()
(interactive)
(message "original"))
(defun local-version ()
(interactive)
(message "local binding"))
;; open new buffer in emacs-lisp mode and set a local key
(defun jump-to-other-buffer ()
(interactive)
(with-current-buffer (get-buffer-create "*test1*")
(emacs-lisp-mode)
;; These change bindings in all elisp buffers
;; (make-local-variable 'emacs-lisp-mode-map)
;; (define-key emacs-lisp-mode-map (kbd "C-c C-c") 'local-version)
;; (local-set-key (kbd "C-c C-c") 'local-version)
(let ((overriding-local-map (copy-keymap emacs-lisp-mode-map)))
(define-key overriding-local-map (kbd "C-c C-c") 'local-version)
(use-local-map overriding-local-map))
(pop-to-buffer (current-buffer))))
;; default binding in elisp buffers
(define-key emacs-lisp-mode-map (kbd "C-c C-c") 'original)
In vim I have this in my .vimrc:
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
How do I get the easy window nav in evil-mode?
Also, in vim "+ will copy to my system clipboard? This doesn't seem to work in emacs.
$ emacs --version
GNU Emacs 24.3.1 Copyright (C) 2013 Free Software Foundation, Inc. GNU
Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies
of Emacs under the terms of the GNU General Public License. For more
information about these matters, see the file named COPYING.
$ cat .emacs
;;
;; Package manager and better repos
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(package-initialize)
(setq backup-directory-alist `(("." . "~/.emacs.d/saves")))
;; Indents, tab as spaces
(setq-default indent-tabs-mode nil)
(setq default-tab-width 2)
;; evil-mode
(eval-after-load "evil"
'(progn
(define-key evil-normal-state-map (kbd "C-h") 'evil-window-left)
(define-key evil-normal-state-map (kbd "C-j") 'evil-window-down)
(define-key evil-normal-state-map (kbd "C-k") 'evil-window-up)
(define-key evil-normal-state-map (kbd "C-l") 'evil-window-right)))
(require 'evil)
(evil-mode 1)
;(setcdr evil-insert-state-map nil)
;(define-key evil-insert-state-map [escape] 'evil-normal-state)
;; Fun stuff
(require 'jabber-autoloads)
(require 'jabber)
You can add the key bindings you want to use to evil-normal-state-map:
(eval-after-load "evil"
'(progn
(define-key evil-normal-state-map (kbd "C-h") 'evil-window-left)
(define-key evil-normal-state-map (kbd "C-j") 'evil-window-down)
(define-key evil-normal-state-map (kbd "C-k") 'evil-window-up)
(define-key evil-normal-state-map (kbd "C-l") 'evil-window-right)))
Wrapping the code into eval-after-load is necessary to ensure that evil-normal-state-map is defined/available when making the calls to define-key.
If you want to make the same bindings available in other "states" (such as "Motion" state) as well, just add them to the corresponding key maps as shown above (in the case of "Motion" state, the corresponding map is called evil-motion-state-map).
To get Emacs to use the system clipboard, try setting x-select-enable-clipboard to a non-nil value:
(setq x-select-enable-clipboard t)
There are also specific commands for killing and yanking that use the clipboard. From the documentation:
clipboard-kill-region:
Kill the region, and save it in the X clipboard.
clipboard-kill-ring-save:
Copy region to kill ring, and save in the X clipboard.
I'm trying to redefine the "M-." in the ENSIME mode so that it runs auto-complete instead of ensime-edit-definition. Which is the default binding. I have the following code in the .emacs:
(defun my-scala-mode()
(ensime-mode)
(local-set-key [return] 'newline-and-indent)
(local-unset-key (kbd "M-."))
(local-set-key (kbd "M-.") 'auto-complete)
(global-unset-key (kbd "M-."))
(global-set-key (kbd "M-.") 'auto-complete)
;(scala-electric-mode)
(yas/minor-mode-on))
(add-hook 'scala-mode-hook 'my-scala-mode)
However, once ensime mode loads, and somehow redefines the keys back to the default. If I comment out "(ensime-mode)" then it maps correctly.
What should I do here? Is there another mode hook I'm missing? Or should the order be different?
Thank you
Apparently ensime-mode is a minor-mode, so its bindings take precedence over the major-mode's bindings. And local-set-key affects the major mode's bindings. You might want to do something like the following (guarantedd 100% untested) instead:
(require 'ensime)
(define-key ensime-mode-map (kbd "M-.") 'auto-complete)
or
(add-hook 'ensime-mode-hook (lambda () (define-key ensime-mode-map (kbd "M-.") nil)))
I have (global-set-key (kbd "RET") 'newline-and-indent) in my .emacs which works fine in all modes but scala-mode(the newest, revision 19295 from svn).
What do I need to change to get it working?
(add-hook 'scala-mode-hook
(lambda () (local-set-key (kbd "RET") 'reindent-then-newline-and-indent)))
The above somewhat fixes the problem. It now indents the line correctly after pressing Enter once, but still doesn't work if there is a blank line above the newline.
In scala-mode, "RET" is bound to scala-newline by default, and this overrides the global key binding set with global-set-key, hence the need for the hook specific to scala-mode. Consider using:
(add-hook 'scala-mode-hook
(lambda () (local-set-key (kbd "RET") 'newline-and-indent)))
instead of:
(add-hook 'scala-mode-hook
(lambda () (local-set-key (kbd "RET") 'reindent-then-newline-and-indent)))
If you don't want Emacs to change your indentation after leaving a line.