0

How can I add multiple lists to global-abbrev-table?

(defconst tablet1 
   '( ("all" "l")     ("as" "as")      ("can" "k")
      ("some" "so")   ("than" "n")     ("that" "ta")
      ("there" "tr")  ("this" "th")    ("time" "ti") ))

(defconst tablet2
   '( ("again" "ag")  ("any" "n")    ("before" "bf")
      ("every" "ev")  ("from" "fm")  ("good" "g")
      ("here" "he")   ("long" "lg")  ("not" "n")
      ("such" "sc")   ("the" "t")    ("would" "d") ))


(defun abbrev ()
  (kill-all-abbrevs)
  (define-abbrev-table 'global-abbrev-table tablet1))

1 Answer 1

0

I would try:

(define-abbrev-table 'global-abbrev-table (append tablet1 tablet2))

The point is that the second argument of define-abbrev-table must be a single list (of two-element lists). append lets you combine two or more such lists into one by concatenating all the argument lists into one list [1].

See the doc string of append with C-h f append:

append is a built-in function in ‘C source code’.

(append &rest SEQUENCES)

Concatenate all the arguments and make the result a list.
The result is a list whose elements are the elements of all the arguments.
Each argument may be a list, vector or string.
The last argument is not copied, just used as the tail of the new list.

BTW, it is now tested and it works fine.


[1] append actually makes copies of all its argument lists except the last. This is irrelevant for the above discussion, but it is important in general. The last argument is "shared" structure: you can get to it through the tablet2 variable and also through the result of append. See the Emacs Lisp manual, section "Building Cons Cells and Lists" for some discussion. You can get to that section with C-h i g (elisp) RET i cons cells RET.

9
  • How can I handle the last argument?
    – Ephram
    Aug 4 at 2:36
  • Have tried it and would still gets changed even if it occurs as the last argument.
    – Ephram
    Aug 4 at 2:40
  • Sorry, what? Why shouldn't it? If you are talking about the "last argument is not copied" note in the doc string of append, that refers to tablet2: the last argument of append: it's a somewhat technical point having to do with shared structure - see the Emacs Lisp manual, section "Building Cons Cells and Lists".
    – NickD
    Aug 4 at 3:45
  • Would I need to add another entry to tablet2?
    – Ephram
    Aug 4 at 10:46
  • Why would you? As I said, it works fine: did you try it?
    – NickD
    Aug 4 at 13:16

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.