From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daiki Ueno Newsgroups: gmane.emacs.devel Subject: Re: epg--status-GET-HIDDEN cleanup suggestion Date: Mon, 18 Aug 2008 10:16:25 +0900 Message-ID: <8763pzi0ly.fsf@broken.deisui.org> References: <873al59iw9.fsf@broken.deisui.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1219022208 6953 80.91.229.12 (18 Aug 2008 01:16:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Aug 2008 01:16:48 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 18 03:17:41 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KUtNL-0000yK-9R for ged-emacs-devel@m.gmane.org; Mon, 18 Aug 2008 03:17:39 +0200 Original-Received: from localhost ([127.0.0.1]:35136 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KUtMO-0001e0-6u for ged-emacs-devel@m.gmane.org; Sun, 17 Aug 2008 21:16:40 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KUtMK-0001dv-MX for emacs-devel@gnu.org; Sun, 17 Aug 2008 21:16:36 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KUtMH-0001dj-Sr for emacs-devel@gnu.org; Sun, 17 Aug 2008 21:16:35 -0400 Original-Received: from [199.232.76.173] (port=46992 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KUtMH-0001dg-Mt for emacs-devel@gnu.org; Sun, 17 Aug 2008 21:16:33 -0400 Original-Received: from ti-out-0910.google.com ([209.85.142.188]:60672) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KUtMH-0005xu-12 for emacs-devel@gnu.org; Sun, 17 Aug 2008 21:16:33 -0400 Original-Received: by ti-out-0910.google.com with SMTP id u5so760201tia.10 for ; Sun, 17 Aug 2008 18:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type :sender; bh=Cf26ROTBRa2zCur0VoEtVqMbVV5xyrhqkiT0lbhmUo0=; b=s7u06LeyN3jphlwIa5JhLhdySvTszusZc88HxAIEQVW5EhJo2hBiR31phnAIYZFFJO qIPW7vLyqWLSGzchIf30QYbUX3Y8fuVQ7+rAXP/zKrjDMiVPEQj86H8gxHrImquRhgig LMSilysPWYe10KoWo/VkfOPcopEVT5dTfuyW4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:sender; b=T+/zlGU0RzV0QUyFMLC+HrRJnI3NEiFJCCUp/pqyr/3LcEs1gF4mVjojGdQXaPbI4A guCeTfd86BPez/wEzwb9fbNyjTGRlungB8CblNZ5uoLiYWzIXhgemnm8kXlJ+70y/tfb IWgiZudjz9tG42biZxUHOxz1GOL+DLh8PYmlw= Original-Received: by 10.110.57.6 with SMTP id f6mr5037666tia.38.1219022190388; Sun, 17 Aug 2008 18:16:30 -0700 (PDT) Original-Received: from p360 ( [150.82.173.253]) by mx.google.com with ESMTPS id a14sm3147604tia.0.2008.08.17.18.16.27 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 17 Aug 2008 18:16:29 -0700 (PDT) In-Reply-To: (Ted Zlatanov's message of "Sat, 16 Aug 2008 11:05:32 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:102570 Archived-At: --=-=-= >>>>> In >>>>> Ted Zlatanov 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=epg-callbacks.diff 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 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 progress-callback) @@ -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." (progn (setq passphrase (funcall - (if (consp (epg-context-passphrase-callback context)) - (car (epg-context-passphrase-callback context)) - (epg-context-passphrase-callback context)) + (car (epg-context-passphrase-callback context)) context epg-key-id - (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]+\\)" string)) - (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)) 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) --=-=-= Regards, -- Daiki Ueno --=-=-=--