diff options
| author | Lars Magne Ingebrigtsen | 2014-12-09 22:32:44 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2014-12-09 22:32:44 +0000 |
| commit | 08a980a4007fe7543cdc47af072dfbd834319927 (patch) | |
| tree | dd5ab0beb59a6d8266780ad72f48f7a9b639b487 | |
| parent | e8acfc7fb4a6c01d50ed121ca5ce2ed41f7b0db9 (diff) | |
| download | emacs-08a980a4007fe7543cdc47af072dfbd834319927.tar.gz emacs-08a980a4007fe7543cdc47af072dfbd834319927.zip | |
lisp/gnus/gnus-art.el: Refactored out gnus-article-mime-handles
| -rw-r--r-- | lisp/gnus/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/gnus/gnus-art.el | 198 |
2 files changed, 104 insertions, 102 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 2f0641f139c..d8dd1d3b5fd 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-12-09 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 2 | |||
| 3 | * gnus-art.el (gnus-article-mime-handles): Refactored out into own | ||
| 4 | function for reuse. | ||
| 5 | (gnus-mime-buttonize-attachments-in-header): Adjusted. | ||
| 6 | |||
| 1 | 2014-12-07 Lars Magne Ingebrigtsen <larsi@gnus.org> | 7 | 2014-12-07 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 8 | ||
| 3 | * message.el (message-change-subject): Really check whether the subject | 9 | * message.el (message-change-subject): Really check whether the subject |
| @@ -13,7 +19,7 @@ | |||
| 13 | 19 | ||
| 14 | * gnus-cloud.el (gnus-cloud): Add :version tag. | 20 | * gnus-cloud.el (gnus-cloud): Add :version tag. |
| 15 | 21 | ||
| 16 | 2014-11-29 John Mastro <john.b.mastro@gmail.com> (tiny change) | 22 | 2014-11-29 John Mastro <john.b.mastro@gmail.com> (tiny change) |
| 17 | 23 | ||
| 18 | * auth-source.el (auth-source-macos-keychain-search-items): Return | 24 | * auth-source.el (auth-source-macos-keychain-search-items): Return |
| 19 | result of `auth-source-macos-keychain-result-append' (bug#19074). | 25 | result of `auth-source-macos-keychain-result-append' (bug#19074). |
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el index 62a60b20111..53da05e939b 100644 --- a/lisp/gnus/gnus-art.el +++ b/lisp/gnus/gnus-art.el | |||
| @@ -6335,6 +6335,40 @@ Provided for backwards compatibility." | |||
| 6335 | (when image | 6335 | (when image |
| 6336 | (gnus-add-image 'shr image)))) | 6336 | (gnus-add-image 'shr image)))) |
| 6337 | 6337 | ||
| 6338 | (defun gnus-article-mime-handles (&optional alist id all) | ||
| 6339 | (if alist | ||
| 6340 | (let ((i 1) newid flat) | ||
| 6341 | (dolist (handle alist flat) | ||
| 6342 | (setq newid (append id (list i)) | ||
| 6343 | i (1+ i)) | ||
| 6344 | (if (stringp (car handle)) | ||
| 6345 | (setq flat (nconc flat (gnus-article-mime-handles | ||
| 6346 | (cdr handle) newid all))) | ||
| 6347 | (delq (rassq handle all) all) | ||
| 6348 | (setq flat (nconc flat (list (cons newid handle))))))) | ||
| 6349 | (let ((flat (list nil))) | ||
| 6350 | ;; Assume that elements of `gnus-article-mime-handle-alist' | ||
| 6351 | ;; are in the decreasing order, but unnumbered subsidiaries | ||
| 6352 | ;; in each element are in the increasing order. | ||
| 6353 | (dolist (handle (reverse gnus-article-mime-handle-alist)) | ||
| 6354 | (if (stringp (cadr handle)) | ||
| 6355 | (setq flat (nconc flat (gnus-article-mime-handles | ||
| 6356 | (cddr handle) (list (car handle)) flat))) | ||
| 6357 | (delq (rassq (cdr handle) flat) flat) | ||
| 6358 | (setq flat (nconc flat (list (cons (list (car handle)) | ||
| 6359 | (cdr handle))))))) | ||
| 6360 | (setq flat (cdr flat)) | ||
| 6361 | (mapc (lambda (handle) | ||
| 6362 | (if (cdar handle) | ||
| 6363 | ;; This is a hidden (i.e. unnumbered) handle. | ||
| 6364 | (progn | ||
| 6365 | (setcar handle | ||
| 6366 | (1+ (caar gnus-article-mime-handle-alist))) | ||
| 6367 | (push handle gnus-article-mime-handle-alist)) | ||
| 6368 | (setcar handle (caar handle)))) | ||
| 6369 | flat) | ||
| 6370 | flat))) | ||
| 6371 | |||
| 6338 | (defun gnus-mime-buttonize-attachments-in-header (&optional interactive) | 6372 | (defun gnus-mime-buttonize-attachments-in-header (&optional interactive) |
| 6339 | "Show attachments as buttons in the end of the header of an article. | 6373 | "Show attachments as buttons in the end of the header of an article. |
| 6340 | This function toggles the display when called interactively. Note that | 6374 | This function toggles the display when called interactively. Note that |
| @@ -6342,108 +6376,70 @@ buttons to be added to the header are only the ones that aren't inlined | |||
| 6342 | in the body. Use `gnus-header-face-alist' to highlight buttons." | 6376 | in the body. Use `gnus-header-face-alist' to highlight buttons." |
| 6343 | (interactive (list t)) | 6377 | (interactive (list t)) |
| 6344 | (gnus-with-article-buffer | 6378 | (gnus-with-article-buffer |
| 6345 | (gmm-labels | 6379 | (let ((case-fold-search t) buttons handle type st) |
| 6346 | ;; Function that returns a flattened version of | 6380 | (save-excursion |
| 6347 | ;; `gnus-article-mime-handle-alist'. | 6381 | (save-restriction |
| 6348 | ((flattened-alist | 6382 | (widen) |
| 6349 | (&optional alist id all) | 6383 | (article-narrow-to-head) |
| 6350 | (if alist | 6384 | ;; Header buttons exist? |
| 6351 | (let ((i 1) newid flat) | 6385 | (while (and (not buttons) |
| 6352 | (dolist (handle alist flat) | 6386 | (re-search-forward "^attachments?:[\n ]+" nil t)) |
| 6353 | (setq newid (append id (list i)) | 6387 | (when (get-char-property (match-end 0) |
| 6354 | i (1+ i)) | 6388 | 'gnus-button-attachment-extra) |
| 6355 | (if (stringp (car handle)) | 6389 | (setq buttons (match-beginning 0)))) |
| 6356 | (setq flat (nconc flat (flattened-alist (cdr handle) | 6390 | (widen) |
| 6357 | newid all))) | 6391 | (when buttons |
| 6358 | (delq (rassq handle all) all) | 6392 | ;; Delete header buttons. |
| 6359 | (setq flat (nconc flat (list (cons newid handle))))))) | 6393 | (delete-region buttons (if (re-search-forward "^[^ ]" nil t) |
| 6360 | (let ((flat (list nil))) | 6394 | (match-beginning 0) |
| 6361 | ;; Assume that elements of `gnus-article-mime-handle-alist' | 6395 | (point-max)))) |
| 6362 | ;; are in the decreasing order, but unnumbered subsidiaries | 6396 | (unless (and interactive buttons) |
| 6363 | ;; in each element are in the increasing order. | 6397 | ;; Find buttons. |
| 6364 | (dolist (handle (reverse gnus-article-mime-handle-alist)) | 6398 | (setq buttons nil) |
| 6365 | (if (stringp (cadr handle)) | 6399 | (dolist (button (gnus-article-mime-handles)) |
| 6366 | (setq flat (nconc flat (flattened-alist (cddr handle) | 6400 | (setq handle (cdr button) |
| 6367 | (list (car handle)) | 6401 | type (mm-handle-media-type handle)) |
| 6368 | flat))) | 6402 | (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer) |
| 6369 | (delq (rassq (cdr handle) flat) flat) | 6403 | (with-current-buffer gnus-summary-buffer |
| 6370 | (setq flat (nconc flat (list (cons (list (car handle)) | 6404 | gnus-inhibit-images) |
| 6371 | (cdr handle))))))) | 6405 | gnus-inhibit-images) |
| 6372 | (setq flat (cdr flat)) | 6406 | (string-match "\\`image/" type)) |
| 6373 | (mapc (lambda (handle) | 6407 | (mm-inline-override-p handle) |
| 6374 | (if (cdar handle) | 6408 | (and (mm-handle-disposition handle) |
| 6375 | ;; This is a hidden (i.e. unnumbered) handle. | 6409 | (not (equal (car (mm-handle-disposition handle)) |
| 6376 | (progn | 6410 | "inline")) |
| 6377 | (setcar handle | 6411 | (not (mm-attachment-override-p handle))) |
| 6378 | (1+ (caar gnus-article-mime-handle-alist))) | 6412 | (not (mm-automatic-display-p handle)) |
| 6379 | (push handle gnus-article-mime-handle-alist)) | 6413 | (not (or (and (mm-inlinable-p handle) |
| 6380 | (setcar handle (caar handle)))) | 6414 | (mm-inlined-p handle)) |
| 6381 | flat) | 6415 | (mm-automatic-external-display-p type)))) |
| 6382 | flat)))) | 6416 | (push button buttons))) |
| 6383 | (let ((case-fold-search t) buttons handle type st) | ||
| 6384 | (save-excursion | ||
| 6385 | (save-restriction | ||
| 6386 | (widen) | ||
| 6387 | (article-narrow-to-head) | ||
| 6388 | ;; Header buttons exist? | ||
| 6389 | (while (and (not buttons) | ||
| 6390 | (re-search-forward "^attachments?:[\n ]+" nil t)) | ||
| 6391 | (when (get-char-property (match-end 0) | ||
| 6392 | 'gnus-button-attachment-extra) | ||
| 6393 | (setq buttons (match-beginning 0)))) | ||
| 6394 | (widen) | ||
| 6395 | (when buttons | 6417 | (when buttons |
| 6396 | ;; Delete header buttons. | 6418 | ;; Add header buttons. |
| 6397 | (delete-region buttons (if (re-search-forward "^[^ ]" nil t) | 6419 | (article-goto-body) |
| 6398 | (match-beginning 0) | 6420 | (forward-line -1) |
| 6399 | (point-max)))) | 6421 | (narrow-to-region (point) (point)) |
| 6400 | (unless (and interactive buttons) | 6422 | (insert "Attachment" (if (cdr buttons) "s" "") ":") |
| 6401 | ;; Find buttons. | 6423 | (dolist (button (nreverse buttons)) |
| 6402 | (setq buttons nil) | 6424 | (setq st (point)) |
| 6403 | (dolist (button (flattened-alist)) | 6425 | (insert " ") |
| 6404 | (setq handle (cdr button) | 6426 | (mm-handle-set-undisplayer |
| 6405 | type (mm-handle-media-type handle)) | 6427 | (setq handle (copy-sequence (cdr button))) nil) |
| 6406 | (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer) | 6428 | (gnus-insert-mime-button handle (car button)) |
| 6407 | (with-current-buffer gnus-summary-buffer | 6429 | (skip-chars-backward "\t\n ") |
| 6408 | gnus-inhibit-images) | 6430 | (delete-region (point) (point-max)) |
| 6409 | gnus-inhibit-images) | 6431 | (when (> (current-column) (window-width)) |
| 6410 | (string-match "\\`image/" type)) | 6432 | (goto-char st) |
| 6411 | (mm-inline-override-p handle) | 6433 | (insert "\n") |
| 6412 | (and (mm-handle-disposition handle) | 6434 | (end-of-line))) |
| 6413 | (not (equal (car (mm-handle-disposition handle)) | 6435 | (insert "\n") |
| 6414 | "inline")) | 6436 | (dolist (ovl (gnus-overlays-in (point-min) (point))) |
| 6415 | (not (mm-attachment-override-p handle))) | 6437 | (gnus-overlay-put ovl 'gnus-button-attachment-extra t) |
| 6416 | (not (mm-automatic-display-p handle)) | 6438 | (gnus-overlay-put ovl 'face nil)) |
| 6417 | (not (or (and (mm-inlinable-p handle) | 6439 | (let ((gnus-treatment-function-alist |
| 6418 | (mm-inlined-p handle)) | 6440 | '((gnus-treat-highlight-headers |
| 6419 | (mm-automatic-external-display-p type)))) | 6441 | gnus-article-highlight-headers)))) |
| 6420 | (push button buttons))) | 6442 | (gnus-treat-article 'head))))))))) |
| 6421 | (when buttons | ||
| 6422 | ;; Add header buttons. | ||
| 6423 | (article-goto-body) | ||
| 6424 | (forward-line -1) | ||
| 6425 | (narrow-to-region (point) (point)) | ||
| 6426 | (insert "Attachment" (if (cdr buttons) "s" "") ":") | ||
| 6427 | (dolist (button (nreverse buttons)) | ||
| 6428 | (setq st (point)) | ||
| 6429 | (insert " ") | ||
| 6430 | (mm-handle-set-undisplayer | ||
| 6431 | (setq handle (copy-sequence (cdr button))) nil) | ||
| 6432 | (gnus-insert-mime-button handle (car button)) | ||
| 6433 | (skip-chars-backward "\t\n ") | ||
| 6434 | (delete-region (point) (point-max)) | ||
| 6435 | (when (> (current-column) (window-width)) | ||
| 6436 | (goto-char st) | ||
| 6437 | (insert "\n") | ||
| 6438 | (end-of-line))) | ||
| 6439 | (insert "\n") | ||
| 6440 | (dolist (ovl (gnus-overlays-in (point-min) (point))) | ||
| 6441 | (gnus-overlay-put ovl 'gnus-button-attachment-extra t) | ||
| 6442 | (gnus-overlay-put ovl 'face nil)) | ||
| 6443 | (let ((gnus-treatment-function-alist | ||
| 6444 | '((gnus-treat-highlight-headers | ||
| 6445 | gnus-article-highlight-headers)))) | ||
| 6446 | (gnus-treat-article 'head)))))))))) | ||
| 6447 | 6443 | ||
| 6448 | ;;; Article savers. | 6444 | ;;; Article savers. |
| 6449 | 6445 | ||