diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ChangeLog | 16 | ||||
-rw-r--r-- | lisp/gnus/ChangeLog | 14 | ||||
-rw-r--r-- | lisp/gnus/auth-source.el | 148 | ||||
-rw-r--r-- | lisp/window.el | 83 |
4 files changed, 217 insertions, 44 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d2d44793366..b5d76e3f533 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,19 @@ +2011-06-16 Martin Rudalics <rudalics@gmx.at> + + * window.el (display-buffer-normalize-specifiers-1): Respect + current value of pop-up-frames for most reasonable values of + second argument of display-buffer (Bug#8865). + (switch-to-buffer-same-frame, switch-to-buffer-other-window) + (switch-to-buffer-other-window-same-frame) + (switch-to-buffer-other-frame): Fix doc-strings. Reported by Drew + Adams (Bug#8875). + (display-buffer): Don't check noninteractive when calling + display-buffer-pop-up-frame. + (display-buffer-pop-up-frame): Never pop up a frame in + noninteractive mode (Bug#8857). + (enlarge-window, shrink-window): Don't report an error when the + window can't be resized as requested (Bug#8862). + 2011-06-15 Stefan Monnier <monnier@iro.umontreal.ca> * pcmpl-rpm.el (pcomplete/rpm): Minor simplification. diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 2bfaf32f958..a160581d861 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog @@ -1,3 +1,17 @@ +2011-06-16 Teodor Zlatanov <tzz@lifelogs.com> + + * auth-source.el (auth-source-save-secrets): New variable to control if + secret tokens should be saved encrypted. + (auth-source-netrc-parse, auth-source-netrc-search): Pass the file name + to `auth-source-netrc-normalize'. + (with-auth-source-epa-overrides): Add convenience macro. Don't depend + on the EPA variables being defined. + (auth-source-epa-make-gpg-token): Convert text to a "gpg:" token. + (auth-source-netrc-normalize): Convert "gpg:" tokens back to text in + the lexical-let closure. + (auth-source-netrc-create): Create "gpg:" tokens according to + `auth-source-save-secrets'. + 2011-06-10 Katsumi Yamaoka <yamaoka@jpl.org> * gnus-group.el (gnus-group-update-group): Add new argument diff --git a/lisp/gnus/auth-source.el b/lisp/gnus/auth-source.el index e0bea324a25..40389bb7f72 100644 --- a/lisp/gnus/auth-source.el +++ b/lisp/gnus/auth-source.el @@ -154,6 +154,16 @@ let-binding." (const :tag "Never save" nil) (const :tag "Ask" ask))) +(defcustom auth-source-save-secrets nil + "If set, auth-source will respect it for password tokens behavior." + :group 'auth-source + :version "23.2" ;; No Gnus + :type `(choice + :tag "auth-source new password token behavior" + (const :tag "Use GPG tokens" gpg) + (const :tag "Save unencrypted" nil) + (const :tag "Ask" ask))) + (defvar auth-source-magic "auth-source-magic ") (defcustom auth-source-do-cache t @@ -898,7 +908,7 @@ Note that the MAX parameter is used so we can exit the parse early." (null require) ;; every element of require is in the normalized list (let ((normalized (nth 0 (auth-source-netrc-normalize - (list alist))))) + (list alist) file)))) (loop for req in require always (plist-get normalized req))))) (decf max) @@ -934,7 +944,54 @@ Note that the MAX parameter is used so we can exit the parse early." (nreverse result)))))) -(defun auth-source-netrc-normalize (alist) +(defmacro with-auth-source-epa-overrides (&rest body) + `(let ((file-name-handler-alist + ',(if (boundp 'epa-file-handler) + (remove (symbol-value 'epa-file-handler) + file-name-handler-alist) + file-name-handler-alist)) + (find-file-hook + ',(remove 'epa-file-find-file-hook find-file-hook)) + (auto-mode-alist + ',(if (boundp 'epa-file-auto-mode-alist-entry) + (remove (symbol-value 'epa-file-auto-mode-alist-entry) + auto-mode-alist) + auto-mode-alist))) + ,@body)) + +(defun auth-source-epa-make-gpg-token (secret file) + (require 'epa nil t) + (unless (featurep 'epa) + (error "EPA could not be loaded.")) + (let* ((base (file-name-sans-extension file)) + (passkey (format "gpg:-%s" base)) + (stash (concat base ".gpg")) + ;; temporarily disable EPA + (stashfile + (with-auth-source-epa-overrides + (make-temp-file "gpg-token" nil + stash))) + (epa-file-passphrase-alist + `((,stashfile + . ,(password-read + (format + "token pass for %s? " + file) + passkey))))) + (write-region secret nil stashfile) + ;; temporarily disable EPA + (unwind-protect + (with-auth-source-epa-overrides + (with-temp-buffer + (insert-file-contents stashfile) + (base64-encode-region (point-min) (point-max) t) + (concat "gpg:" + (buffer-substring-no-properties + (point-min) + (point-max))))) + (delete-file stashfile)))) + +(defun auth-source-netrc-normalize (alist filename) (mapcar (lambda (entry) (let (ret item) (while (setq item (pop entry)) @@ -950,15 +1007,65 @@ Note that the MAX parameter is used so we can exit the parse early." ;; send back the secret in a function (lexical binding) (when (equal k "secret") - (setq v (lexical-let ((v v)) - (lambda () v)))) - - (setq ret (plist-put ret - (intern (concat ":" k)) - v)) - )) - ret)) - alist)) + (setq v (lexical-let ((v v) + (filename filename) + (base (file-name-nondirectory + filename)) + (token-decoder nil) + (gpgdata nil) + (stash nil)) + (setq stash (concat base ".gpg")) + (when (string-match "gpg:\\(.+\\)" v) + (require 'epa nil t) + (unless (featurep 'epa) + (error "EPA could not be loaded.")) + (setq gpgdata (base64-decode-string + (match-string 1 v))) + ;; it's a GPG token + (setq + token-decoder + (lambda (gpgdata) +;;; FIXME: this relies on .gpg files being handled by EPA/EPG + (let* ((passkey (format "gpg:-%s" base)) + ;; temporarily disable EPA + (stashfile + (with-auth-source-epa-overrides + (make-temp-file "gpg-token" nil + stash))) + (epa-file-passphrase-alist + `((,stashfile + . ,(password-read + (format + "token pass for %s? " + filename) + passkey))))) + (unwind-protect + (progn + ;; temporarily disable EPA + (with-auth-source-epa-overrides + (write-region gpgdata + nil + stashfile)) + (setq + v + (with-temp-buffer + (insert-file-contents stashfile) + (buffer-substring-no-properties + (point-min) + (point-max))))) + (delete-file stashfile))) + ;; clear out the decoder at end + (setq token-decoder nil + gpgdata nil)))) + (lambda () + (when token-decoder + (funcall token-decoder gpgdata)) + v)))) + (setq ret (plist-put ret + (intern (concat ":" k)) + v)))) + ret)) + alist)) ;;; (setq secret (plist-get (nth 0 (auth-source-search :host t :type 'netrc :K 1 :max 1)) :secret)) ;;; (funcall secret) @@ -982,7 +1089,8 @@ See `auth-source-search' for details on SPEC." :file (oref backend source) :host (or host t) :user (or user t) - :port (or port t))))) + :port (or port t)) + (oref backend source)))) ;; if we need to create an entry AND none were found to match (when (and create @@ -1098,7 +1206,21 @@ See `auth-source-search' for details on SPEC." (cond ((and (null data) (eq r 'secret)) ;; Special case prompt for passwords. - (read-passwd prompt)) + ;; Respect `auth-source-save-secrets' + (let* ((ep (format "Do you want GPG password tokens? (%s)" + "see `auth-source-save-secrets'")) + (gpg-encrypt +;;; FIXME: this relies on .gpg files being handled by EPA/EPG + ;; don't put GPG tokens in GPG-encrypted files + (and (not (equal "gpg" (file-name-extension file))) + (or (eq auth-source-save-secrets 'gpg) + (and (eq auth-source-save-secrets 'ask) + (setq auth-source-save-secrets + (and (y-or-n-p ep) 'gpg)))))) + (plain (read-passwd prompt))) + (if (eq auth-source-save-secrets 'gpg) + (auth-source-epa-make-gpg-token plain file) + plain))) ((null data) (when default (setq prompt diff --git a/lisp/window.el b/lisp/window.el index 5493893d4c1..aa874b8e503 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -2044,7 +2044,18 @@ make selected window wider by DELTA columns. If DELTA is negative, shrink selected window by -DELTA lines or columns. Return nil." (interactive "p") - (resize-window (selected-window) delta horizontal)) + (cond + ((zerop delta)) + ((window-size-fixed-p nil horizontal) + (error "Selected window has fixed size")) + ((window-resizable-p nil delta horizontal) + (resize-window nil delta horizontal)) + (t + (resize-window + nil (if (> delta 0) + (window-max-delta nil horizontal) + (- (window-min-delta nil horizontal))) + horizontal)))) (defun shrink-window (delta &optional horizontal) "Make selected window DELTA lines smaller. @@ -2054,7 +2065,18 @@ make selected window narrower by DELTA columns. If DELTA is negative, enlarge selected window by -DELTA lines or columns. Return nil." (interactive "p") - (resize-window (selected-window) (- delta) horizontal)) + (cond + ((zerop delta)) + ((window-size-fixed-p nil horizontal) + (error "Selected window has fixed size")) + ((window-resizable-p nil (- delta) horizontal) + (resize-window nil (- delta) horizontal)) + (t + (resize-window + nil (if (> delta 0) + (- (window-min-delta nil horizontal)) + (window-max-delta nil horizontal)) + horizontal)))) (defun maximize-window (&optional window) "Maximize WINDOW. @@ -3453,9 +3475,8 @@ specific buffers." ;; (bw-finetune wins) ;; (message "Done in %d rounds" round) )) - - +;;; Displaying buffers. (defconst display-buffer-default-specifiers '((reuse-window nil same visible) (pop-up-window (largest . nil) (lru . nil)) @@ -4705,7 +4726,8 @@ non-nil means to make a new frame on graphic displays only. SPECIFIERS must be a list of buffer display specifiers, see the documentation of `display-buffer-alist' for a description." - (unless (and graphic-only (not (display-graphic-p))) + (unless (or (and graphic-only (not (display-graphic-p))) + noninteractive) (let* ((selected-window (selected-window)) (function (or (cdr (assq 'pop-up-frame-function specifiers)) 'make-frame)) @@ -4909,9 +4931,12 @@ BUFFER-OR-NAME and return that buffer." (defun display-buffer-normalize-specifiers-1 (specifiers) "Subroutine of `display-buffer-normalize-specifiers'. SPECIFIERS is the SPECIFIERS argument of `display-buffer'." - (let (normalized) + (let (normalized entry) (cond + ((not specifiers) + nil) ((listp specifiers) + ;; If SPECIFIERS is a list, we assume it is a list of specifiers. (dolist (specifier specifiers) (cond ((consp specifier) @@ -4924,21 +4949,17 @@ SPECIFIERS is the SPECIFIERS argument of `display-buffer'." (dolist (item (cdr entry)) (setq normalized (cons item normalized))))))) ;; Reverse list. - (setq normalized (nreverse normalized))) - ;; The two cases below must come from the SPECIFIERS argument of - ;; `display-buffer'. - ((eq specifiers 't) - ;; Historically t means "other window". Eventually we should get - ;; rid of this. - (setq normalized - (cdr (assq 'other-window display-buffer-macro-specifiers)) - normalized)) - ((symbolp specifiers) - ;; We allow scalar specifiers in calls of `display-buffer'. - (let ((entry (assq specifiers display-buffer-macro-specifiers))) - (when entry (setq normalized (cdr entry)))))) - - normalized)) + (nreverse normalized)) + ((and (not (eq specifiers 'other-window)) + (setq entry (assq specifiers display-buffer-macro-specifiers))) + ;; A macro specifier. + (cdr entry)) + ((with-no-warnings (memq pop-up-frames '(nil unset))) + ;; Pop up a new window. + (cdr (assq 'other-window display-buffer-macro-specifiers))) + (t + ;; Pop up a new frame. + (cdr (assq 'other-frame display-buffer-macro-specifiers)))))) (defun display-buffer-normalize-specifiers-2 (&optional buffer-or-name) "Subroutine of `display-buffer-normalize-specifiers'. @@ -5301,8 +5322,8 @@ this list as arguments." ;; Try reusing a window not showing BUFFER on any visible or ;; iconified frame. (display-buffer-reuse-window buffer '(nil other 0)) - ;; Try making a new frame (but not in batch mode). - (and (not noninteractive) (display-buffer-pop-up-frame buffer)) + ;; Try making a new frame. + (display-buffer-pop-up-frame buffer) ;; Try using a weakly dedicated window. (display-buffer-reuse-window buffer '(nil nil t) '((reuse-window-dedicated . weak))) @@ -5513,8 +5534,8 @@ functions should call `pop-to-buffer-same-window' instead." (defun switch-to-buffer-same-frame (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME in a window on the selected frame. Another frame will be used only if there is no other choice. -Optional arguments BUFFER-OR-NAME and NORECORD have the same -meaning as for `switch-to-buffer'. +Arguments BUFFER-OR-NAME and NORECORD have the same meaning as +for `switch-to-buffer'. This function is intended for interactive use only. Lisp functions should call `pop-to-buffer-same-frame' instead." @@ -5527,8 +5548,8 @@ functions should call `pop-to-buffer-same-frame' instead." "Switch to buffer BUFFER-OR-NAME in another window. The selected window will be used only if there is no other choice. Windows on the selected frame are preferred to windows -on other frames. Optional arguments BUFFER-OR-NAME and NORECORD -have the same meaning as for `switch-to-buffer'. +on other frames. Arguments BUFFER-OR-NAME and NORECORD have the +same meaning as for `switch-to-buffer'. This function is intended for interactive use only. Lisp functions should call `pop-to-buffer-other-window' instead." @@ -5540,8 +5561,8 @@ functions should call `pop-to-buffer-other-window' instead." (defun switch-to-buffer-other-window-same-frame (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME in another window on the selected frame. The selected window or another frame will be used only if there -is no other choice. Optional arguments BUFFER-OR-NAME and -NORECORD have the same meaning as for `switch-to-buffer'. +is no other choice. Arguments BUFFER-OR-NAME and NORECORD have +the same meaning as for `switch-to-buffer'. This function is intended for interactive use only. Lisp functions should call `pop-to-buffer-other-window-same-frame' @@ -5554,8 +5575,8 @@ instead." (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME on another frame. The same frame will be used only if there is no other choice. -Optional arguments BUFFER-OR-NAME and NORECORD have the same -meaning as for `switch-to-buffer'. +Arguments BUFFER-OR-NAME and NORECORD have the same meaning +as for `switch-to-buffer'. This function is intended for interactive use only. Lisp functions should call `pop-to-buffer-other-frame' instead." |