2

I frequently work with R and ess, and want to bind a shortcut to a function that clears the R console:

(use-package ess-site
  :ensure ess
  :bind (:map inferior-ess-mode-map
              ("C-c c" . clear-shell)
              )
  )

However, the keybinding is not set when I start emacs. I have to launch an inferior-ess-mode, then go to my config file and evaluate the code above for it to bind the function to "C-c c".

How can this be fixed?

Edit:

It also does not work if I use something that is not bound to anything, like C-c s. Also, there is no difference if I use :bind*. Only after I manually execute the code above it works. Same thing happens if I use another mode map, like ess-mode-map.

Also, the same thing happens with other modes and functions, like this for matlab:

(use-package matlab-mode
  :ensure t
  :config
  (load-library "matlab-load")
  (custom-set-variables
   '(matlab-shell-command-switches '("-nodesktop -nosplash")))
  (add-hook 'matlab-mode-hook 'auto-complete-mode)
  (setq auto-mode-alist
        (cons
         '("\\.m$" . matlab-mode)
         auto-mode-alist))
  (matlab-cedet-setup)
  :bind* (:map matlab-mode-map
               ("C-c C-c" . matlab-shell-save-and-go))
  )

The keybinding C-c C-c only works after manually evaluating the code while the matlab shell is already running. Before that it's bound to the function that it's bound to by default in that mode.

2 Answers 2

3

I think the problem is that loading ess-site doesn't automatically load ess-inf at the same time and it is ess-inf.el where inferior-ess-mode-map is defined. Try this instead:

(use-package ess-site :ensure ess)

(use-package ess-inf
  :bind (:map inferior-ess-mode-map
         ("C-c c" . clear-shell)))
0
1

Your bind probably is not being set up because there's another command bound to this shortcut.

You can type C-h k to execute the describe-key function and then type C-c c (your shortcut) to find out what's the correct command that's bound this shortcut. Note that you need to be into the major/minor mode that you want to check it out.

So if you decide that you really want to override it, you can use bind* from use-package.

From use-package docs:

:bind            Bind keys, and define autoloads for the bound commands.
:bind*           Bind keys, and define autoloads for the bound commands,
                 *overriding all minor mode bindings*.
:bind-keymap     Bind a key prefix to an auto-loaded keymap defined in the
                 package.  This is like ‘:bind’, but for keymaps.
:bind-keymap*    Like ‘:bind-keymap’, but overrides all minor mode bindings
1
  • Thanks, but It still does not works, I made an edit to the question.
    – Florian
    Sep 23, 2018 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.