branch: externals/cus-abbrev
commit adcb943b287c887c47553b2cf901c48deaed9d58
Author: Mauro Aranda <maurooara...@gmail.com>
Commit: Mauro Aranda <maurooara...@gmail.com>

    Preserve :count when defining abbrevs
    
    * cus-abbrev.el (Custom-abbrev-define): Save :count of each abbrev
    before clearing the table.
---
 cus-abbrev.el | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/cus-abbrev.el b/cus-abbrev.el
index 8847b152ee..93d5a6b70b 100644
--- a/cus-abbrev.el
+++ b/cus-abbrev.el
@@ -108,14 +108,29 @@ See `custom-commands' for further explanation.")
   "Define abbrevs in current buffer, without saving them."
   (interactive)
   (dolist (widget custom-abbrev-widgets)
-    (let ((table (symbol-value (widget-get widget :custom-abbrev-table))))
-      (clear-abbrev-table table)
+    (let ((table (symbol-value (widget-get widget :custom-abbrev-table)))
+          (count nil))
+      ;; Get current count for all abbrevs to be defined.
       (dolist (abbrev-widget (widget-get widget :children))
-        (let ((abbrev (widget-value abbrev-widget)))
-          (define-abbrev table (nth 0 abbrev) (nth 1 abbrev)
-            (nth 2 abbrev)
-            :enable-function (nth 3 abbrev)
-            :case-fixed (nth 4 abbrev))))))
+        (let* ((abbrev (widget-value abbrev-widget))
+               (symname (nth 0 abbrev))
+               (sym (obarray-get table symname))
+               (plist (symbol-plist sym)))
+          (push (plist-get plist :count) count)))
+      (setq count (nreverse count))
+      ;; We clear the abbrev table so that we can make sure removed
+      ;; abbrevs are not present anymore.
+      (clear-abbrev-table table)
+      (let ((i 0))
+        (dolist (abbrev-widget (widget-get widget :children))
+          (let ((abbrev (widget-value abbrev-widget)))
+            (define-abbrev table (nth 0 abbrev) (nth 1 abbrev)
+              (nth 2 abbrev)
+              :enable-function (nth 3 abbrev)
+              :case-fixed (nth 4 abbrev)
+              ;; We effectively preserve count of each redefined abbrev.
+              :count (nth i count))
+            (setq i (1+ i)))))))
   (message "Abbrevs defined, but not saved"))
 
 (defun Custom-abbrev-revert-buffer (&rest _ignored)

Reply via email to