emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/subed 8120fb429f 04/22: Use defalias for non-interactive f


From: ELPA Syncer
Subject: [nongnu] elpa/subed 8120fb429f 04/22: Use defalias for non-interactive functions
Date: Tue, 1 Feb 2022 14:05:33 -0500 (EST)

branch: elpa/subed
commit 8120fb429fd535f08eff77817760b7998ffaa039
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>

    Use defalias for non-interactive functions
    
    * subed/subed-common.el (subed-define-generic-function): Use defalias
    for non-interactive functions to simplify looking up a function.
---
 subed/subed-common.el | 43 ++++++++++++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/subed/subed-common.el b/subed/subed-common.el
index bfc3a46f0b..baaf723651 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -39,25 +39,34 @@
 (defvar-local subed--regexp-separator nil "Regexp separating subtitles.")
 (defvar-local subed--regexp-timestamp nil "Regexp matching timestamps.")
 
-(defmacro subed-define-generic-function (name args doc &rest body)
+(defmacro subed-define-generic-function (name args &rest body)
   "Declare an object method and provide the old way of calling it."
   (declare (indent 2))
-  `(progn
-     (cl-defgeneric ,(intern (concat "subed--" (symbol-name name)))
-         ,args
-       ,doc
-       ,@(if (eq (caar body) 'interactive)
-             (cdr body)
-           body))
-     (defun ,(intern (concat "subed-" (symbol-name name))) ,args
-       ,doc
-       ,(if (eq (caar body) 'interactive)
-            (car body))
-       (,(intern (concat "subed--" (symbol-name name)))
-        ,@(delq nil (mapcar (lambda (a)
-                              (unless (string-match "^&" (symbol-name a))
-                                a))
-                            args))))))
+  (let (is-interactive
+        doc)
+    (when (stringp (car body))
+      (setq doc (pop body)))
+    (setq is-interactive (eq (caar body) 'interactive))
+    `(progn
+       (cl-defgeneric ,(intern (concat "subed--" (symbol-name name)))
+           ,args
+         ,doc
+         ,@(if is-interactive
+               (cdr body)
+             body))
+       ,(if is-interactive
+            `(defun ,(intern (concat "subed-" (symbol-name name))) ,args
+               ,(concat doc "\n\nThis function calls the generic function `"
+                        (concat "subed--" (symbol-name name)) "' for the 
actual implementation.")
+               ,(car body)
+               (,(intern (concat "subed--" (symbol-name name)))
+                ,@(delq nil (mapcar (lambda (a)
+                                      (unless (string-match "^&" (symbol-name 
a))
+                                        a))
+                                    args))))
+          `(defalias (quote ,(intern (concat "subed-" (symbol-name name))))
+             (quote ,(intern (concat "subed--" (symbol-name name))))
+             ,doc)))))
 
 (subed-define-generic-function timestamp-to-msecs (time-string)
   "Find timestamp pattern in TIME-STRING and convert it to milliseconds.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]