unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* epg--status-GET-HIDDEN cleanup suggestion
@ 2008-08-16 13:17 Ted Zlatanov
  2008-08-16 13:41 ` Daiki Ueno
  0 siblings, 1 reply; 4+ messages in thread
From: Ted Zlatanov @ 2008-08-16 13:17 UTC (permalink / raw)
  To: emacs-devel; +Cc: Daiki Ueno

[-- Attachment #1: Type: text/plain, Size: 232 bytes --]

The function epg--status-GET-HIDDEN in epg.el had lots of repetition, so
I cleaned it up a little with a let*.  I don't know the protocol for
comitting these cleanups, so I offer the patch for review.  It works for
me.

Thanks
Ted


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: epg.el.patch --]
[-- Type: text/x-patch, Size: 4419 bytes --]

Index: epg.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/epg.el,v
retrieving revision 1.6
diff -c -r1.6 epg.el
*** epg.el	6 May 2008 07:57:34 -0000	1.6
--- epg.el	16 Aug 2008 13:14:25 -0000
***************
*** 1228,1282 ****
  (defun epg--status-GET_HIDDEN (context string)
    (when (and epg-key-id
  	     (string-match "\\`passphrase\\." string))
!     (unless (epg-context-passphrase-callback context)
!       (error "passphrase-callback not set"))
!     (let (inhibit-quit
! 	  passphrase
! 	  passphrase-with-new-line
! 	  encoded-passphrase-with-new-line)
!       (unwind-protect
! 	  (condition-case nil
! 	      (progn
! 		(setq passphrase
! 		      (funcall
! 		       (if (consp (epg-context-passphrase-callback context))
! 			   (car (epg-context-passphrase-callback context))
! 			 (epg-context-passphrase-callback context))
! 		       context
! 		       epg-key-id
! 		       (if (consp (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)
! 		  (setq passphrase nil)
! 		  (if epg-passphrase-coding-system
! 		      (progn
! 			(setq encoded-passphrase-with-new-line
! 			      (epg--encode-coding-string
! 			       passphrase-with-new-line
! 			       (coding-system-change-eol-conversion
! 				epg-passphrase-coding-system 'unix)))
! 			(epg--clear-string passphrase-with-new-line)
! 			(setq passphrase-with-new-line nil))
! 		    (setq encoded-passphrase-with-new-line
! 			  passphrase-with-new-line
! 			  passphrase-with-new-line nil))
! 		  (process-send-string (epg-context-process context)
! 				       encoded-passphrase-with-new-line)))
! 	    (quit
! 	     (epg-context-set-result-for
! 	      context 'error
! 	      (cons '(quit)
! 		    (epg-context-result-for context 'error)))
! 	     (delete-process (epg-context-process context))))
! 	(if passphrase
! 	    (epg--clear-string passphrase))
! 	(if passphrase-with-new-line
! 	    (epg--clear-string passphrase-with-new-line))
! 	(if encoded-passphrase-with-new-line
! 	    (epg--clear-string encoded-passphrase-with-new-line))))))
! 
  (defun epg--prompt-GET_BOOL (context string)
    (let ((entry (assoc string epg-prompt-alist)))
      (y-or-n-p (if entry (cdr entry) (concat string "? ")))))
--- 1228,1278 ----
  (defun epg--status-GET_HIDDEN (context string)
    (when (and epg-key-id
  	     (string-match "\\`passphrase\\." string))
!     (let* ((context-callback (epg-context-passphrase-callback context))
! 	   (callback (or (car-safe context-callback) context-callback))
! 	   (file (cdr-safe context-callback)))
!       (unless context-callback
! 	(error "passphrase-callback not set"))
!       (let (inhibit-quit
! 	    passphrase
! 	    passphrase-with-new-line
! 	    encoded-passphrase-with-new-line)
! 	(unwind-protect
! 	    (condition-case nil
! 		(progn
! 		  (setq passphrase
! 			(funcall callback context epg-key-id file))
! 		  (when passphrase
! 		    (setq passphrase-with-new-line (concat passphrase "\n"))
! 		    (epg--clear-string passphrase)
! 		    (setq passphrase nil)
! 		    (if epg-passphrase-coding-system
! 			(progn
! 			  (setq encoded-passphrase-with-new-line
! 				(epg--encode-coding-string
! 				 passphrase-with-new-line
! 				 (coding-system-change-eol-conversion
! 				  epg-passphrase-coding-system 'unix)))
! 			  (epg--clear-string passphrase-with-new-line)
! 			  (setq passphrase-with-new-line nil))
! 		      (setq encoded-passphrase-with-new-line
! 			    passphrase-with-new-line
! 			    passphrase-with-new-line nil))
! 		    (process-send-string (epg-context-process context)
! 					 encoded-passphrase-with-new-line)))
! 	      (quit
! 	       (epg-context-set-result-for
! 		context 'error
! 		(cons '(quit)
! 		      (epg-context-result-for context 'error)))
! 	       (delete-process (epg-context-process context))))
! 	  (if passphrase
! 	      (epg--clear-string passphrase))
! 	  (if passphrase-with-new-line
! 	      (epg--clear-string passphrase-with-new-line))
! 	  (if encoded-passphrase-with-new-line
! 	      (epg--clear-string encoded-passphrase-with-new-line)))))))
!   
  (defun epg--prompt-GET_BOOL (context string)
    (let ((entry (assoc string epg-prompt-alist)))
      (y-or-n-p (if entry (cdr entry) (concat string "? ")))))

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-08-18  1:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-16 13:17 epg--status-GET-HIDDEN cleanup suggestion Ted Zlatanov
2008-08-16 13:41 ` Daiki Ueno
2008-08-16 16:05   ` Ted Zlatanov
2008-08-18  1:16     ` Daiki Ueno

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).