2

I'm creating custom major mode derived from js-mode which comes with it's own menu entry "Javascript" (top-level entry, between Tools & Help (sorry, not sure what the correct name for that UI element is)).

I would like to hide/remove that menu since I don't have need for it (deriving from js-mode mostly for indentation settings which I know is probably an overkill).

I found this piece of information here:

(define-key global-map [menu-bar words] nil)

so I have tried calling

(define-key global-map [menu-bar javascript] nil)

from inside define-derived-mode and my-mode-hook, but neither option worked (javascript menu bar name was guessed based on the UI label as I am not sure where can I check the actual name).

Any ideas on what I'm doing wrong with this approach? Or perhaps there is another way to hide/remove menu items?

0

Assuming your major mode is defined with something like:

(defvar my-mode-map
  (let ((map (make-sparse-keymap)))
    <my-own-bindings>
    map))

(define-derived-mode my-mode js-mode "My"
  "Major mode for My language."
  <my-own-settings>)

then you can try to put

(define-key map [menu-bar JavaScript] #'undefined)

somewhere within the <my-own-bindings>.

  • defvar my-mode-map... code didn't work "out of the box" but it pointed me in the right direction - checking how to create own key map. Also had to add (use-local-map my-mode-map) within <my-own-settings> to actually activate new key map. – IvanR Dec 14 '17 at 9:11
  • define-derived-mode already does the use-local-map for you, so you probably have a bug elsewhere [ BTW, the defvar above had a missing paren at the end of the line that starts with (let, which probably explains your problem with it ]. – Stefan Dec 14 '17 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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