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)
Related
What can I add to my init.el to move the cursor to the very first character of the open buffer when I press s-up (i.e. hold "command" key, press "up" key on macOS), and equivalent for s-down?
I know it should be something like (global-set-key (kbd "s-<up>") ... )
(global-set-key (kbd "s-<up>") 'beginning-of-buffer)
(global-set-key (kbd "s-<down>") 'end-of-buffer)
You can find out what command a given key is bound to by using C-h k.
In this case, M-< takes you to the beginning of the buffer, and C-h k M-< tells you this:
M-< runs the command beginning-of-buffer, which is an interactive
compiled Lisp function in simple.el.
It is bound to begin, C-home, M-<, menu-bar search goto beg-of-buf.
(beginning-of-buffer &optional ARG)
Move point to the beginning of the buffer.
With numeric arg N, put point N/10 of the way from the beginning.
If the buffer is narrowed, this command uses the beginning of the
accessible part of the buffer.
If Transient Mark mode is disabled, leave mark at previous
position, unless a C-u prefix is supplied.
Don't use this command in Lisp programs!
(goto-char (point-min)) is faster.
Similarly, for M->, which is bound to end-of-buffer.
I simply want to clear the repl buffer so that a single prompt eg (user>) is left on the first line.
I have a keybinding:
(put 'erase-buffer 'disabled nil)
(global-set-key (kbd "C-x C-<backspace>") 'erase-buffer)
But this gives the message :
text is read only
There is the option C-c C-o but this only clears the last return value.
When using python, and run-python the following command C-x M-o which i believe is comint-clear-buffer
cider-repl.el provides a function cider-repl-clear-buffer which by default is bound to:
M-x c-r--bu RET
as C-c M-b is not used by cider-repl as far as I am aware:
(add-hook 'cider-repl-mode-hook
'(lambda () (define-key cider-repl-mode-map (kbd "C-c M-b")
'cider-repl-clear-buffer)))
cider-repl.el also provides cider-repl-handle-shortcut which is bound to ,.
Which will prompt you to many commands, such as clear (which you want), ns (to change namespace), refresh, reload and many others
I find pressing , followd by enter (to choose clear, faster/more convenient than the other answer.)
Note: you need to type , into the repl while the line is empty, it works for both evil and normal emacs keybinds
I want to bind GUI dialog File -> Open File to Ctrl + o
I can (global-set-key (kbd "C-o") 'find-file) but I want it exactly with gui.
How can I do it?
File -> Open File is just a GUI binding to find-file.
By binding it to "C-o", you can then open a file using "C-o". However, this will only bring up the standard find-file interface, which uses the echo area.
In order to also get a GUI dialogue box, you need to get emacs to think that find-file has been clicked, rather than invoked by keyboard. The solution to that can be found in
Emacs M-x commands for invoking "GUI-style" menus.
Putting the two together (i.e. put them in your .emacs file and evaluate them):
(global-set-key (kbd "C-o") 'find-file)
(defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
"Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
(let ((last-nonmenu-event nil))
ad-do-it))
Note, C-o is already bound to open-line - which will 'insert a newline and leave point before it`.
Following the comment by #squidy, here is the complete answer to what the OP asks (tested on emacs 24.3.1):
(global-set-key (kbd "C-o") 'menu-find-file-existing)
(defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
"Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
(let ((last-nonmenu-event nil))
ad-do-it))
I wanted to change the behaviour of Ctrl-d key. So it will delete a word backward. I created a function:
(defun backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument ARG, do this that many times."
(interactive "p")
(delete-region (point) (progn (backward-word arg) (point))))
Then inserted this into emacs.d:
(global-set-key (kbd "\C-d") 'backward-delete-word)
It works in fundamental-mode, but in php-mode it just removes the next character. When I click
Ctrl-h k Ctrl-d
Emacs gives this:
C-d runs the command c-electric-delete-forward, which is an
interactive compiled Lisp function in `cc-cmds.el'.
It is bound to C-d.
(c-electric-delete-forward ARG)
Somehow, it was reset to another function. How to find out, where it was reset and make it work with my function instead?
I don't have php-mode so I can't say for sure, but the binding is likely overriden in php-mode-map (which, as a major mode map, has higher precedence than the global map).
You can check by using C-h b to list all available key bindings and look for C-d or c-electric-delete-forward in the output buffer to see in which keymap the binding is defined.
Assuming php-mode-map overrides the C-d binding, you can disable it using
(define-key php-mode-map (kbd "C-d") nil)
I need to check if Shift key is pressed.
More exactly I would like to set dired switches depending on whether Shift is pressed.
(defadvice find-file-noselect (around find-file-noselect-set-switches activate)
(let ((switches dired-listing-switches))
;; check if shift is pressed and set or not an "R" switch
(setq dired-listing-switches "-lhRA")
ad-do-it
(setq dired-listing-switches switches)))
Of course, I can have different shortcuts for different dired switches, but I would like to change my switches dynamically during choosing a directory for dired.
Duplicate question (ignoring the 'Windows' part of the other one).
Can I send a keypress to Windows from Emacs?
The best you can do (is as you mention) have different shortcuts. They can be differentiated by capitalization... for example
(global-set-key (kbd "C-x C-D") 'dired-with-some-switches)
(global-set-key (kbd "C-x C-d") 'dired-with-other-switches)