4

In .spacemacs I am trying to define a few custom, major mode mappings, that can be accesed using SPC m. This is working fine for org-mode:

  (evil-leader/set-key-for-mode 'org-mode "l" 'org-insert-link)

but when I define it for a different mode it doesn't work:

  (evil-leader/set-key-for-mode 'sclang-mode "sl" 'sclang-eval-line)

Using SPC m just returns SPC m is undefined

UPDATE:

The mode is part of a package that I used following these instructions. In my .spacemacs file I have added these lines to make it work:

(add-to-list 'load-path "~/.emacs.d/sc/el")
(require 'sclang)
(setenv "PATH" (concat (getenv "PATH") ":/Applications/SuperCollider/SuperCollider.app/Contents/Resources"))
(setq exec-path (append exec-path '("/Applications/SuperCollider"  "/Applications/SuperCollider/SuperCollider.app/Contents/Resources" )))

It also required to move a folder in the .emacs.d folder (and I need to remove it temporarily before every spacemacs update...) so yes, definitely not even close to an official layer.

Dionysis
  • 328
  • 3
  • 11
  • 1
    Can you use set-key-for-mode to bind multi-key combos? Does "sl" work in org-mode, or does it only work for single keys? – Tyler Apr 20 '16 at 17:51
  • 1
    @Tyler You are right sl is not working in org-mode either. Nevertheless even when I put just l for sclang-mode I get SPC m is undefined – Dionysis Apr 20 '16 at 18:00

3 Answers3

1

I finally solved this with help from the Spacemacs Gitter channel.

There was a deeper issue with the definition of the major mode itself. More specifically (quoting NJBS's answer on Gitter):

Your issue is that sclang-mode doesn't define itself properly by deriving from fundamental-mode, but rather it defines itself using defun. You can change sclang-mode.el's mode definition to the following and your bindings should stick:

(define-derived-mode sclang-mode fundamental-mode "sclang-mode"
  "Major mode for editing SuperCollider language code.
\\{sclang-mode-map}
"
  (sclang-mode-set-local-variables)
  (sclang-set-font-lock-keywords)
  (sclang-init-document)
  (sclang-make-document))

Link to the commit where I fixed the issue.

Dionysis
  • 328
  • 3
  • 11
0

Try using:

(spacemacs/set-leader-keys-for-major-mode 'sclang-mode "sl" 'sclang-eval-line)

I am using that on several of my modes and all is displayed properly.

** UPDATE ** The problem you are having is most likely because you are not creating a spacemacs layer, and instead are trying to use the traditional Emacs way of configuration.

To add this to your configuration, you need to create a custom layer. This is the Spacemacs way.

Have a look here for help: https://github.com/syl20bnr/spacemacs/blob/master/doc/LAYERS.org

MaDhAt2r
  • 21
  • 4
  • That is not working I'm afraid... Am I right to assume that there must be a conflict with the package for sclang-mode? Is there a way to trace the problem? – Dionysis May 19 '16 at 10:58
  • @Dionysis would you please run M-x spacemacs/report-issue and paste the output in your original post? Also, is sclang-mode a custom layer you have created or is it a spacemacs included layer? – MaDhAt2r May 19 '16 at 13:26
  • I added a bit more info in the original post. The spacemacs/report-issue takes me to GitHub. I did not go through to avoid creating an unnecessary report. It seems to me that this is going to end up being something for the sclang-mode creator to sort out and not for the spacemacs developers. – Dionysis May 19 '16 at 15:56
  • @Dionysis I have updated my answer. You should create a layer. – MaDhAt2r May 20 '16 at 00:18
  • I finally returned to this and created the layer. It is all working well but putting the line you suggested in keybindings.el of my layer is still not registering it. When I look up the functions they are still bound to the default keys... Any ideas? – Dionysis Sep 27 '16 at 21:57
  • @Dionysis define your keys in your packages.el file under the init function for the package. refer to the URL I posted in answer. – MaDhAt2r Oct 11 '16 at 13:43
  • I did read the docs carefully and tried everything I can I am afraid. If it turns out that it was my mistake in the layer definition I will change the right answer back to yours. Thanks for the help anyway! – Dionysis Oct 13 '16 at 12:58
0

I think you're likely right that it's an upstream bug, as was the case here:

https://github.com/syl20bnr/spacemacs/issues/6943

Braham Snyder
  • 360
  • 3
  • 9
  • 1
    I think you might be right... It is a shame that there is a gap and a package working on emacs does not always work on spacemacs. It seems that to resolve it I will have to get into elispwhen time allows and check the source of the package. – Dionysis Oct 13 '16 at 12:55