11

At the cost of an extra top-level symbol binding, there's a very neat solution which avoids repeating the define-derived-mode form: (defalias 'my-fancy-parent-mode (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode)) (define-derived-mode my-fancy-mode my-fancy-parent-mode ...) Works fine in any Emacs >= 23. I came up with this for haml-mode a ...


10

Does it mean that C programming is running under prog-mode and c-mode? No, because, as you later quote: Major modes are mutually exclusive; each buffer has one and only one major mode at any time. So your buffer can only be in one or the other. Is prog-mode a universal mode for all the programs? No, it is a universal parent mode for all programming ...


6

All you have to do is add (run-hooks 'prog-mode-hook) to erlang-mode-hook: (add-hook 'erlang-mode-hook (lambda () (run-hooks 'prog-mode-hook))) You should place this after anything else you add to erlang-mode-hook to make sure prog-mode-hook gets called before anything else. That way erlang-mode can clobber any settings in prog-mode that it ...


5

In addition to answers given by @erikstokes and @Abbrev, you might want to add the following: (put 'erlang-mode 'derived-mode-parent 'prog-mode) It ensures that (derived-mode-p 'prog-mode) returns t for Erlang mode. This is useful since there are a number of utilities that are enabled for all modes that inherit from Prog mode. However, a more permanent ...


4

erlang-mode probably doesn't inherit prog-mode-abbrev-table correctly, so any abbrevs you create for prog-mode won't work. Fix like so: (eval-after-load erlang-mode (abbrev-table-put erlang-abbrev-table :parents (list prog-mode-abbrev-table))) This bug is shared by python-mode and lisp-mode, and they ship with Emacs!


3

See C-hv process-environment List of overridden environment variables for subprocesses to inherit. Each element should be a string of the form ENVVARNAME=VALUE. Entries in this list take precedence to those in the frame-local environments. Therefore, let-binding process-environment is an easy way to temporarily change the value of an ...


3

tl;dr: Use if and your own init function: (if (fboundp 'prog-mode) (define-derived-mode your-cool-mode prog-mode "Cool" "Docstring" (your-cool--init)) (define-derived-mode your-cool-mode nil "Cool" "Docstring" (your-cool--init))) Then do all the mode's initialization in your-cool-init. Longer explanation: The problem is that the ...


3

One possibility to achieve what I wanted is to have (add-hook 'text-mode-hook 'visual-line-mode) in addition to (defun my-prog-mode-hook () (setq truncate-lines t)) (add-hook 'prog-mode-hook #'my-prog-mode-hook) which wraps long lines in text-mode while truncating them in programming modes. Beware not to have any (global-visual-line-...


2

Using yasnippet You did not mention what programming language major mode you are working in. So let me provide an example for c-mode. First time setup Step 1: Install yasnippet You will need to install the yasnippet package (also available from Melpa) to implement the below solution. Check out this wonderful introduction to yasnippet especially if you ...


2

I usually use smartparens for this. First, write in your if statement, leaving the point where the pipe | is: if (condition) {|} foo(); bar(); Then call the function sp-slurp-hybrid-sexp twice: if (condition) { foo(); bar(); } See the smartparens wiki page for more info on "hybrid s-exps".


Only top voted, non community-wiki answers of a minimum length are eligible