Subject: bug#45693: [two word expansion works, but write-abbrev-file destroys it]

From: Robert Pluim <[email-masked]>
Date: Mon, 11 Jan 2021 18:38:57 +0100

Uwe Brauer <[email-masked]> writes:

>> So does it mean we had better avoid describing this "feature" in the
>> docs, until and unless it gets fixed to be more user-friendly?
>
> Well, I find it useful and found a real kludge by using two abbrev files
> and associated minor modes. I think what is *really* missing is to 
> improve/rewrite the write-abbrev-file function.

At the very least we need to support :regexp and
:case-fixed. Something like this, maybe?

diff --git i/lisp/abbrev.el w/lisp/abbrev.el
index 65f7118385..21b4af095f 100644
--- i/lisp/abbrev.el
+++ w/lisp/abbrev.el
@@ -1074,7 +1074,11 @@ insert-abbrev-table-description
 a call to `define-abbrev-table' that when evaluated will define
 the abbrev table NAME exactly as it is currently defined.
 Abbrevs marked as \"system abbrevs\" are ignored."
-  (let ((symbols (abbrev--table-symbols name readable)))
+  (let* ((symbols (abbrev--table-symbols name readable))
+        (docstring (or (documentation-property name 'variable-documentation)
+                       "no documentation"))
+        (sym (obarray-get (symbol-value name) ""))
+        (props (symbol-plist sym)))
     (setq symbols (sort symbols 'string-lessp))
     (let ((standard-output (current-buffer)))
       (if readable
@@ -1090,7 +1094,13 @@ insert-abbrev-table-description
             (insert " '())\n\n")
           (insert "\n  '(\n")
           (mapc 'abbrev--write symbols)
-          (insert "   ))\n\n")))
+          (insert "   )\n")
+          (insert (format "%S\n" docstring))
+          (when (plist-member props :case-fixed)
+            (insert (format "%s %s\n" :case-fixed (plist-get props :case-fixed))))
+          (when (plist-member props :regexp)
+            (insert (format "%s %S\n" :regexp (plist-get props :regexp))))
+          (insert ")\n\n")))
       nil)))
 
 (defun abbrev--table-symbols (name &optional system)