From: Katsumi Yamaoka Date: Wed, 24 May 2006 12:33:23 +0000 (+0000) Subject: * gnus-art.el (gnus-default-article-saver): Doc fix. X-Git-Url: https://cgit.sxemacs.org/?a=commitdiff_plain;h=d59739f869bca85ad2a7b268f2d40dcc4373425d;p=gnus * gnus-art.el (gnus-default-article-saver): Doc fix. (gnus-article-save-coding-system): Move from gnus-sum.el, rename from gnus-summary-save-article-coding-system, and default to a certain coding system. (gnus-output-to-file): Add coding cookie and encode text according to gnus-article-save-coding-system; don't use mm-append-to-file. * gnus-sum.el (gnus-summary-save-article-coding-system): Move to gnus-art.el and rename to gnus-article-save-coding-system. (gnus-summary-save-article): Require gnus-art; don't show all headers if it decodes articles; don't add coding cookie here; don't bind mm-text-coding-system-for-write. (gnus-summary-save-article-file): Save decoded articles. (gnus-summary-write-article-file): When saving many files, use gnus-summary-write-to-file first and gnus-summary-save-in-file thereafter unless gnus-prompt-before-saving is always. (gnus-summary-save-article-body-file): Save decoded articles. * lpath.el: Fbind select-safe-coding-system for XEmacs. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d703110ff..5ec8589fa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,25 @@ +2006-05-24 Katsumi Yamaoka + + * gnus-art.el (gnus-default-article-saver): Doc fix. + (gnus-article-save-coding-system): Move from gnus-sum.el, rename + from gnus-summary-save-article-coding-system, and default to a + certain coding system. + (gnus-output-to-file): Add coding cookie and encode text according + to gnus-article-save-coding-system; don't use mm-append-to-file. + + * gnus-sum.el (gnus-summary-save-article-coding-system): Move to + gnus-art.el and rename to gnus-article-save-coding-system. + (gnus-summary-save-article): Require gnus-art; don't show all + headers if it decodes articles; don't add coding cookie here; + don't bind mm-text-coding-system-for-write. + (gnus-summary-save-article-file): Save decoded articles. + (gnus-summary-write-article-file): When saving many files, use + gnus-summary-write-to-file first and gnus-summary-save-in-file + thereafter unless gnus-prompt-before-saving is always. + (gnus-summary-save-article-body-file): Save decoded articles. + + * lpath.el: Fbind select-safe-coding-system for XEmacs. + 2006-05-23 Reiner Steib * nnrss.el (nnrss-check-group): Bind hash-index. diff --git a/lisp/gnus-art.el b/lisp/gnus-art.el index 85a67f90f..569d0ab69 100644 --- a/lisp/gnus-art.el +++ b/lisp/gnus-art.el @@ -529,8 +529,8 @@ will be kept while the rest will be deleted before saving." (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail "A function to save articles in your favourite format. -The function must be interactively callable (in other words, it must -be an Emacs command). +The function will be called by way of the `gnus-summary-save-article' +command, and friends such as `gnus-summary-save-article-rmail'. Gnus provides the following functions: @@ -551,6 +551,44 @@ Gnus provides the following functions: (function-item gnus-summary-write-to-file) (function))) +(defcustom gnus-article-save-coding-system + (or (mm-coding-system-p 'utf-8) + (mm-coding-system-p 'iso-2022-7bit) + (mm-coding-system-p 'emacs-mule) + (mm-coding-system-p 'escape-quoted)) + "Coding system used to save decoded articles to a file. + +The recommended coding systems are `utf-8', `iso-2022-7bit' and so on, +which can safely encode any characters in text. This is used by the +commands including: + +* gnus-summary-save-article-file +* gnus-summary-save-article-body-file +* gnus-summary-write-article-file + +and the functions to which you may set `gnus-default-article-saver': + +* gnus-summary-save-in-file +* gnus-summary-save-body-in-file +* gnus-summary-write-to-file + +Those commands and functions save just text displayed in the article +buffer to a file if the value of this variable is non-nil. Note that +buttonized MIME parts will be lost in a saved file in that case. +Otherwise, raw articles will be saved." + :group 'gnus-article-saving + :type `(choice + :format "%{%t%}:\n %[Value Menu%] %v" + (const :tag "Save raw articles" nil) + ,@(delq nil + (mapcar + (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg)) + '((const :tag "UTF-8" utf-8) + (const :tag "iso-2022-7bit" iso-2022-7bit) + (const :tag "Emacs internal" emacs-mule) + (const :tag "escape-quoted" escape-quoted)))) + (symbol :tag "Coding system"))) + (defcustom gnus-rmail-save-name 'gnus-plain-save-name "A function generating a file name to save articles in Rmail format. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE." @@ -5445,17 +5483,55 @@ Provided for backwards compatibility." ;;; Article savers. (defun gnus-output-to-file (file-name) - "Append the current article to a file named FILE-NAME." - (let ((artbuf (current-buffer))) + "Append the current article to a file named FILE-NAME. +If `gnus-article-save-coding-system' is non-nil, it is used to encode +text and used as the value of the coding cookie which is added to the +top of a file. Otherwise, this function saves a raw article without +the coding cookie." + (let* ((artbuf (current-buffer)) + (file-name-coding-system nnmail-pathname-coding-system) + (coding gnus-article-save-coding-system) + (coding-system-for-read (if coding + nil ;; Rely on the coding cookie. + mm-text-coding-system)) + (coding-system-for-write (or coding + mm-text-coding-system-for-write + mm-text-coding-system)) + (exists (file-exists-p file-name))) (with-temp-buffer + (when exists + (insert-file-contents file-name) + (goto-char (point-min)) + ;; Remove the existing coding cookie. + (when (looking-at "X-Gnus-Coding-System: .+\n\n") + (delete-region (match-beginning 0) (match-end 0)))) + (goto-char (point-max)) (insert-buffer-substring artbuf) ;; Append newline at end of the buffer as separator, and then ;; save it to file. (goto-char (point-max)) (insert "\n") - (let ((file-name-coding-system nnmail-pathname-coding-system)) - (mm-append-to-file (point-min) (point-max) file-name)) - t))) + (when coding + ;; If the coding system is not suitable to encode the text, + ;; ask a user for a proper one. + (when (fboundp 'select-safe-coding-system) + (setq coding (coding-system-base + (save-window-excursion + (select-safe-coding-system (point-min) (point-max) + coding)))) + (setq coding-system-for-write + (or (cdr (assq coding '((mule-utf-8 . utf-8)))) + coding))) + (goto-char (point-min)) + ;; Add the coding cookie. + (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n" + coding-system-for-write))) + (if exists + (progn + (write-region (point-min) (point-max) file-name nil 'no-message) + (message "Appended to %s" file-name)) + (write-region (point-min) (point-max) file-name)))) + t) (defun gnus-narrow-to-page (&optional arg) "Narrow the article buffer to a page. diff --git a/lisp/gnus-sum.el b/lisp/gnus-sum.el index ec72ae09e..40b75bee7 100644 --- a/lisp/gnus-sum.el +++ b/lisp/gnus-sum.el @@ -11229,29 +11229,20 @@ Argument REVERSE means reverse order." ;; Summary saving commands. -(defcustom gnus-summary-save-article-coding-system nil - "Coding system used to save a decoded article to a file. -This is used when the `gnus-summary-write-article-file' command is run. -The recommended coding systems include `utf-8', `iso-2022-7bit', and so -forth. Note that buttonized MIME parts will be lost in a saved file. -If it is nil, raw articles will be saved." - :type '(choice :format "%{%t%}:\n %[Value Menu%] %v" - (const :tag "Save raw articles" nil) - (const :tag "UTF-8" utf-8) - (const :tag "iso-2022-7bit" iso-2022-7bit) - (const :tag "Emacs internal" emacs-mule) - (symbol :tag "Coding system")) - :group 'gnus-article-saving) - (defun gnus-summary-save-article (&optional n not-saved decode) "Save the current article using the default saver function. If N is a positive number, save the N next articles. If N is a negative number, save the N previous articles. If N is nil and any articles have been marked with the process mark, save those articles instead. -The variable `gnus-default-article-saver' specifies the saver function." +The variable `gnus-default-article-saver' specifies the saver function. + +If the optional second argument NOT-SAVED is non-nil, articles saved +will not be marked as saved. If the optional third argument DECODE is +non-nil, articles will be decoded before saving." (interactive "P") - (unless gnus-summary-save-article-coding-system + (require 'gnus-art) + (unless gnus-article-save-coding-system (setq decode nil)) (let* ((articles (gnus-summary-work-articles n)) (save-buffer (save-excursion @@ -11271,22 +11262,14 @@ The variable `gnus-default-article-saver' specifies the saver function." gnus-display-mime-function)) (gnus-article-prepare-hook (when decode gnus-article-prepare-hook))) - (gnus-summary-select-article t nil nil article))) + (gnus-summary-select-article (not decode) nil nil article))) (save-excursion (set-buffer save-buffer) (erase-buffer) - (if decode - (progn - (insert "X-Coding-System: -*- coding: " - (symbol-name gnus-summary-save-article-coding-system) - "; -*-\n") - (insert-buffer-substring gnus-article-buffer)) - (insert-buffer-substring gnus-original-article-buffer))) - (let ((mm-text-coding-system-for-write - (if decode - gnus-summary-save-article-coding-system - mm-text-coding-system-for-write))) - (setq file (gnus-article-save save-buffer file num))) + (insert-buffer-substring (if decode + gnus-article-buffer + gnus-original-article-buffer))) + (setq file (gnus-article-save save-buffer file num)) (gnus-summary-remove-process-mark article) (unless not-saved (gnus-summary-set-saved-mark article)))) @@ -11343,7 +11326,7 @@ save those articles instead." (interactive "P") (require 'gnus-art) (let ((gnus-default-article-saver 'gnus-summary-save-in-file)) - (gnus-summary-save-article arg))) + (gnus-summary-save-article arg nil t))) (defun gnus-summary-write-article-file (&optional arg) "Write the current article to a file, deleting the previous file. @@ -11353,7 +11336,17 @@ If N is nil and any articles have been marked with the process mark, save those articles instead." (interactive "P") (require 'gnus-art) - (let ((gnus-default-article-saver 'gnus-summary-write-to-file)) + ;; When saving many files, use `gnus-summary-write-to-file' first + ;; and `gnus-summary-save-in-file' thereafter unless + ;; `gnus-prompt-before-saving' is `always'. + (let ((gnus-default-article-saver + (if (eq gnus-prompt-before-saving 'always) + 'gnus-summary-write-to-file + (lambda (&rest args) + (prog1 + (apply 'gnus-summary-write-to-file args) + (setq gnus-default-article-saver + 'gnus-summary-save-in-file)))))) (gnus-summary-save-article arg nil t))) (defun gnus-summary-save-article-body-file (&optional arg) @@ -11365,7 +11358,7 @@ save those articles instead." (interactive "P") (require 'gnus-art) (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file)) - (gnus-summary-save-article arg))) + (gnus-summary-save-article arg nil t))) (defun gnus-summary-muttprint (&optional arg) "Print the current article using Muttprint. diff --git a/lisp/lpath.el b/lisp/lpath.el index 2a948c2ba..7db113c0a 100644 --- a/lisp/lpath.el +++ b/lisp/lpath.el @@ -37,7 +37,8 @@ mail-abbrevs-setup mouse-minibuffer-check mouse-movement-p mouse-scroll-subr overlay-lists posn-point posn-window read-event set-buffer-multibyte - select-frame-set-input-focus track-mouse window-edges)) + select-frame-set-input-focus select-safe-coding-system + track-mouse window-edges)) (maybe-bind '(adaptive-fill-first-line-regexp buffer-display-table buffer-file-coding-system current-language-environment cursor-in-non-selected-windows