markdown-mode defines tab-width using a magic number when loaded, overwriting any global settings I have (namely, 2 spaces):

(define-derived-mode markdown-mode text-mode "Markdown"
"Major mode for editing Markdown files."
;; Natural Markdown tab width
(setq tab-width 4)

This doesn't seem to be something I can advise on load. A load-hook also seems kind of hacky, and shadowing a specific copy of this file makes it brittle against updates. (Forking and submitting a PR is sort of a roundabout way too.)

What's a set-and-forget way to clobber this setting so that it obeys the global setting?


In general, the major-mode hooks run after the primary major-mode is established. Thus, you can reset the tab-width to 2 afterwards -- it happens so fast, you'll never see that it was set to 4 for a split second prior thereto.

If you really want to take complete control, you may wish to consider creating your own major-mode. In the meantime, the following is the emacs-way to modify a setting established by a major-mode.

(defun my-markdown-settings ()
  (setq tab-width 2))

(add-hook 'markdown-mode-hook 'my-markdown-settings)

SIDE-NOTE:  Most people seem to prefer treating the source-code as sacred, and they enjoy checking for updates and updating the source code when updates by the author become available. If the original poster is so inclined, another solution would be to modify the source code and re-byte-compile (if needed).

| improve this answer | |

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.