[Top][All Lists]

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

Re: epg--status-GET-HIDDEN cleanup suggestion

From: Daiki Ueno
Subject: Re: epg--status-GET-HIDDEN cleanup suggestion
Date: Mon, 18 Aug 2008 10:16:25 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

>>>>> In <address@hidden> 
>>>>>   Ted Zlatanov <address@hidden> wrote:

> Lines of code are not the only measure of code cleanliness; in this
> specific case I found your logic hard to read while debugging an
> unrelated problem so I tried to clean it up.

You appear to be shortsighted.  epg-context-* and epg-context-set-* are
close to simple getter/setter functions of defstruct in CL (see the
definition of epg-context-*).  It looks even unnatural for me to use a
temporary variable just to refer a slot value.

Anyway, I'm going to commit the following change, which ensures
the PASSPHRASE-CALLBACK slot have a cons-cell, and reduces the call to
`epg-context-passphrase-callback' to 3 times.

diff --git a/lisp/epg.el b/lisp/epg.el
index b7d9732..7ad0d34 100644
--- a/lisp/epg.el
+++ b/lisp/epg.el
@@ -185,7 +185,7 @@
   (cons 'epg-context
        (vector (or protocol 'OpenPGP) armor textmode include-certs
                cipher-algorithm digest-algorithm compress-algorithm
-               #'epg-passphrase-callback-function
+               (list #'epg-passphrase-callback-function)
                nil nil nil nil nil nil)))
@@ -328,7 +328,9 @@ This function is for internal use only."
   "Set the function used to query passphrase."
   (unless (eq (car-safe context) 'epg-context)
     (signal 'wrong-type-argument (list 'epg-context-p context)))
-  (aset (cdr context) 7 passphrase-callback))
+  (aset (cdr context) 7 (if (consp passphrase-callback)
+                           passphrase-callback
+                         (list passphrase-callback))))
 (defun epg-context-set-progress-callback (context
@@ -336,7 +338,9 @@ This function is for internal use only."
 If optional argument HANDBACK is specified, it is passed to PROGRESS-CALLBACK."
   (unless (eq (car-safe context) 'epg-context)
     (signal 'wrong-type-argument (list 'epg-context-p context)))
-  (aset (cdr context) 8 progress-callback))
+  (aset (cdr context) 8 (if (consp progress-callback)
+                           progress-callback
+                         (list progress-callback))))
 (defun epg-context-set-signers (context signers)
   "Set the list of key-id for signing."
@@ -1239,13 +1243,10 @@ This function is for internal use only."
                (setq passphrase
-                      (if (consp (epg-context-passphrase-callback context))
-                          (car (epg-context-passphrase-callback context))
-                        (epg-context-passphrase-callback context))
+                      (car (epg-context-passphrase-callback context))
-                      (if (consp (epg-context-passphrase-callback context))
-                          (cdr (epg-context-passphrase-callback context)))))
+                      (cdr (epg-context-passphrase-callback context))))
                (when passphrase
                  (setq passphrase-with-new-line (concat passphrase "\n"))
                  (epg--clear-string passphrase)
@@ -1493,16 +1494,13 @@ This function is for internal use only."
   (if (and (epg-context-progress-callback context)
           (string-match "\\`\\([^ ]+\\) \\([^ ]\\) \\([0-9]+\\) \\([0-9]+\\)"
-      (funcall (if (consp (epg-context-progress-callback context))
-                  (car (epg-context-progress-callback context))
-                (epg-context-progress-callback context))
+      (funcall (car (epg-context-progress-callback context))
               (match-string 1 string)
               (match-string 2 string)
               (string-to-number (match-string 3 string))
               (string-to-number (match-string 4 string))
-              (if (consp (epg-context-progress-callback context))
-                  (cdr (epg-context-progress-callback context))))))
+              (cdr (epg-context-progress-callback context)))))
 (defun epg--status-ENC_TO (context string)
   (if (string-match "\\`\\([0-9A-Za-z]+\\) \\([0-9]+\\) \\([0-9]+\\)" string)
Daiki Ueno

reply via email to

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