I'd like to use the key binding M-n p for ess-swv-purl in .Rmd documents and thus tried (define-key global-set-key (kbd "M-n p") 'ess-swv-purl). If I'm in an .Rmd (Rmarkdown) document, M-n p still shows (M-n p is undefined).
I understand that global key settings are overwritten in many ways, but if the key combination is not bound, where is the problem? (I can execute the function with M-x ess-swv-purl). In case this helps, C-h b shows that M-n is a "Prefix Command" under poly-markdown+r-mode. I tried something like (define-key poly-markdown+r-mode-map (kbd "M-n p") 'ess-swv-purl) (which was just a guess, I don't know what should come after define-key in this case) but then get
Warning (initialization): An error occurred while loading ‘/Users/<user>/.emacs’:
Symbol's value as variable is void: poly-markdown+r-mode-map
(with-eval-after-load "poly-markdown+r-mode" (bind-key "M-n p" #'ess-swv-purl poly-markdown+r-mode-map)), but I still getM-n p is undefined. And what do you mean by 'defining library'? – Marius Hofert Feb 20 '19 at 13:08(with-eval-after-load "poly-R" (bind-key "M-n p" #'ess-swv-purl poly-markdown+R-mode-map))– Tyler Feb 20 '19 at 14:52File mode specification error: (void-function bind-key)in the*Messages*buffer. I also tried(with-eval-after-load "poly-R" (define-key poly-markdown+R-mode-map (kbd "M-n p") #'ess-swv-purl))becausebind-keyrequires an extra library I believe. – Marius Hofert Feb 20 '19 at 20:02bind-keyor cause it to be loaded before you use that function. Or just use the vanilla Emacs functiondefine-key, as you said - you don't needbind-key. – Drew Feb 20 '19 at 21:24M-nis apparently a prefix key in the mode you want, it's likely that there is a specific variable bound to the keymap thatM-nis bound to. In that case, just bindpin that keymap. You need to investigate the code a bit, to find out what you should be doing. You need to know what keymap you're binding a key in. – Drew Feb 20 '19 at 21:27