I use multiple programming languages, and there are a considerable number of abbreviations that I use across all of their corresponding major mode (they are usually name of certain variables, but not limited to this category). One way of customizing Emacs is as follows: As explained here one needs to this in an Elisp file (see the example below) and load it in the init file.
Example Elisp file for storing the abbreviations (ignore that the syntax for the specified languages is not correct):
(when (boundp 'python-mode-abbrev-table)
(clear-abbrev-table python-mode-abbrev-table))
(define-abbrev-table 'python-mode-abbrev-table
("p" "fmt.Printf(\"%v\\n\", hh▮)")
("pl" "fmt.Println(hh▮)")
("r" "return")
("st" "string")
("eq" "==")
("v" "var x = 3")
("df" "x := 3")
("c" "const x = 3")
))
(when (boundp 'matlab-mode-abbrev-table)
(clear-abbrev-table matlab-mode-abbrev-table))
(define-abbrev-table 'matlab-mode-abbrev-table
("p" "fmt.Printf(\"%v\\n\", hh▮)")
("pl" "fmt.Println(hh▮)")
("r" "return")
("st" "string")
("eq" "==")
("v" "var x = 3")
("df" "x := 3")
("c" "const x = 3")
))
(set-default 'abbrev-mode t)
(setq save-abbrevs nil)
But then if you want to expand the list, you need to copy them for abbreviation of all major mode. Is there any way that I maintain only one list, and somehow call them for the needed major modes (maybe the solution is something like the \input{}
in latex).
By the way, I prefer not to use the solution proposed here, as the usual/traditional way to set up abbreviations in Emacs was not very efficient for me (of course if I don't manage to find any other way I may have to use it).
Furthermore, each major mode can have its own abbrev table on top of the common one. In particular, I don't want any of the major modes to inherit all the abbreviations used in other modes (because language syntax is different in each language). Ideally, I'm trying to have something like this (I don't know any Elisp syntax, so ignore!):
;; Common ones
(when (boundp 'python-mode-abbrev-table OR matlab-mode-abbrev-table)
(define-abbrev-table 'python-mode-abbrev-table AND matlab-mode-abbrev-table
("p" "fmt.Printf(\"%v\\n\", hh▮)")
("pl" "fmt.Println(hh▮)")
("r" "return")
("st" "string")
("eq" "==")
("v" "var x = 3")
("df" "x := 3")
("c" "const x = 3")
))
;; Python specific ones
(when (boundp 'python-mode-abbrev-table)
(define-abbrev-table 'python-mode-abbrev-table
("p" "fmt.Printf(\"%v\\n\", hh▮)")
("pl" "fmt.Println(hh▮)")
))
;; MATLAB specific ones
(when (boundp 'matlab-mode-abbrev-table)
(define-abbrev-table 'matlab-mode-abbrev-table
("p" "fmt.Printf(\"%v\\n\", hh▮)")
("pl" "fmt.Println(hh▮)")
))
(set-default 'abbrev-mode t)
(setq save-abbrevs nil)
I'm new to Emacs (and this is the first time posting here), so sorry if the question and the way I phrase it is too naive!