Bind RET to send scheme code in emacs - emacs

I want to set up my .emacs so that when I am in my *scheme* buffer I can bind RET to C-x C-e (because I use C-j for newlines). I get to the scheme buffer like this:
M-x load-library RET xscheme RET note - how can I automate that step?
M-x run-scheme
Here's what I tried, it doesn't work:
(eval-after-load 'xscheme
'(define-key scheme-mode-map
(kbd "RET")
'advertised-xscheme-send-previous-expression))

Seems strange to bind it like that.
Here's how it's done in Emacs 24.4:
(eval-after-load 'cmuscheme
(define-key inferior-scheme-mode-map
(kbd "RET") 'scheme-send-last-sexp))

Related

Minor mode overriding another minor mode key binding

I installed Jedi mode in Emacs. I noticed that it overrides C-c . and C-c , (goto-definition and goto-definition-pop-marker respectively).
Here is how I set it up in my init file:
(setq jedi:setup-keys t)
(add-hook 'python-mode-hook 'jedi:setup)
I am using another mode called multiple-cursors that is set up as follows:
(add-to-list 'load-path "~/.emacs.d/multiple-cursors.el/")
(global-set-key (kbd "C-c .") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c ,") 'mc/mark-previous-like-this)
Once jedi-setup loads, it rebinds my C-c . and C-c ,. What I'd like to do is keep my multiple cursors bindings and remap Jedi's bindings. I tried adding this to the end of my Jedi setup but it ends up mapping the Jedi functions to both C-c./, and C-c j/k at the same time.
(setq jedi:key-goto-definition (kbd "C-c k"))
(setq jedi:key-goto-definition-pop-marker (kbd "C-c j"))
The reason this happens is because Jedi binds them on the regular C-c ./, mappings, then just adds another C-c j/k mapping.
How do I stop Jedi from completely not binding to the C-c ./, and only bind to C-c j/k?
Unbind the keys you want in the Jedi mode keymap: just bind them to nil in that map.
Or change the order of the entries in minor-mode-map-alist.
See (elisp) Controlling Active Maps.

Bind C-z in evil mode to escape to shell

In Emacs evil mode, the key combo C-z is to toggle evil mode. I would like to rebind it to escape to shell instead. How would I do this ?
I have read about eshell, it seems to be great, but for now I would like to work with my zsh shell first.
Multi term seems to designed for this job, but I think escaping to shell is fine for me, since I'm used to this flow in Vim.
Thanks for reading.
Perhaps what you need is C-x C-z.
Just have the same requirement, and here's my configurations:
(add-to-list 'load-path "~/.emacs.d/evil")
(add-to-list 'load-path "~/.emacs.d/evil/lib")
(setq evil-toggle-key ""); remove default evil-toggle-key C-z, manually setup later
(require 'evil)
(evil-mode 1)
;; remove all keybindings from insert-state keymap, use emacs-state when editing
(setcdr evil-insert-state-map nil)
;; ESC to switch back normal-state
(define-key evil-insert-state-map [escape] 'evil-normal-state)
Ref:
1. https://gist.github.com/kidd/1828878
2. https://askubuntu.com/questions/99160/how-to-remap-emacs-evil-mode-toggle-key-from-ctrl-z
C-x C-z will suspend the frame and return you to the shell.
C-z as you mention toggles evil mode on/off.
I swap their behavior in evil like so:
(define-key evil-motion-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-emacs-state-map (kbd "C-z") 'suspend-frame)
(define-key evil-motion-state-map (kbd "C-x C-z") 'evil-emacs-state)
(define-key evil-emacs-state-map (kbd "C-x C-z") 'evil-exit-emacs-state)
See this commit for an example (where I also make C-z emulate vim-behavior in insert/replace mode).

Key binding to reload .emacs after changing it?

As a novice Emacs user (I'm about 3 months into what's probably a lifelong journey), I make changes to my .emacs file pretty regularly. It would be handy to have a global key binding to reload .emacs rather than go through the incredibly laborious process of M-x load-file (delete a long string if I'm deep into some directory) ~/.emacs <RET>. I've attempted a solution, but
;; reload .emacs when C-c <f12> is pressed
(defun reload-dotemacs ()
(load-file "~/.emacs"))
(global-set-key (kbd "C-c <f12>")
(lambda() (interactive) 'reload-dotemacs))
doesn't seem to work. Basically, when I enter the key combination, nothing happens, whereas trying M-x load-file ~/.emacs makes things happen (e.g. I see my yasnippet files reload).
For the record, C-c <f12> doesn't seem to be bound to anything else.
Fix for your code
(defun reload-dotemacs ()
(interactive)
(load-file "~/.emacs"))
(global-set-key (kbd "C-c <f12>") 'reload-dotemacs)
You do not need it 1
You do not need to remove the default string when you do M-x load-file RET - just type ~/.emacs.el RET and it will work.
You do not need it 2
Do not reload the init file, just evaluate the new code.
Type C-h m and C-h b in the .emacs.el buffer and you will see the useful keybindings (after searching for eval):
C-c C-b eval-current-buffer
C-c C-r eval-region
C-M-x eval-defun
C-j eval-print-last-sexp
C-x C-e eval-last-sexp

Defining key binding with arguments

I want to map C-f C-b as moving forward and backward by a fixed amount of lines in a file.
I did this:
(global-set-key (kbd "C-f") 'next-line)
(global-set-key (kbd "C-b") 'previous-line)
but I don't know how to specify an argument before the next-line command. I guess I should use digit-argument but I am unable to write the command in a correct way.
You've changed your question to be about how to bind directly to key sequences
This binds C-c l to C-u 5 C-n
(global-set-key (kbd "C-c l") (kbd "C-u 5 C-n"))
One of the possible alternatives would be define a new function:
(defun my-next-line ()
(interactive)
(next-line 5))
(global-set-key (kbd "C-f") 'my-next-line)
Otherwise, if it is just something you can accomplish with the keyboard you might want to use
M-x name-last-kbd-macro
and save it in your .emacs file
M-x insert-kbd-macro
and have emacs implement the function for you.
It will just get the name you gave in your call to name-last-kbd-macro

how can I kill all 'buffers' in my emacs

Is there a command to kill all buffers in my emacs? instead of having me doing 'Ctrl -k ' one by one until there is no more buffer?
Thank you.
M-x ibuffer RET
tDy
I highly recommend binding C-xC-b to ibuffer as a replacement for the default binding:
(global-set-key (kbd "C-x C-b") 'ibuffer)
(I've also bound my <menu> key to ibuffer, as I use it so often.)
n.b. You can use C-k and x in the regular list-buffers to mark and kill buffers, but I think everyone should be using ibuffer, really.
I am using this function to kill all the buffers in emacs
(defun nuke-all-buffers ()
(interactive)
(mapcar 'kill-buffer (buffer-list))
(delete-other-windows))
(global-set-key (kbd "C-x K") 'nuke-all-buffers)
Works fine for me :-)
Highly hack-ish, but does what you want:
(defun my-kill-everything ()
(interactive)
(dolist (cur (buffer-list))
(kill-buffer cur)))
Note that Emacs always needs at least one buffer, so you'll end up with an empty scratch buffer again. (Yes, this command also kills stuff like the minibuffer, but it will be restored. As I've written: highly hack-ish.)