Mercurial > emacs
diff lisp/mh-e/mh-letter.el @ 68465:37d03b3298bf
The Great Cleanup
Remove circular dependencies.
mh-e.el now includes few require statements and stands alone. Other
files should need to require mh-e.el, which requires mh-loaddefs.el,
plus variable-only files such as mh-scan.el.
Remove unneeded require statements.
Remove unneeded load statements, or replace them with non-fatal
require statements.
Break out components into their own files that were often spread
between many files. As a result, many functions that are now only used
within a single file no longer need to be autoloaded.
Rearrange and provide consistent headings.
Untabify.
* mh-acros.el: Update commentary to reflect current usage. Add
autoload cookies to all macros.
(mh-require-cl): Merge docstring and comment.
(mh-do-in-xemacs): Fix typo in docstring.
(assoc-string): Move to new file mh-compat.el.
(with-mh-folder-updating, mh-in-show-buffer)
(mh-do-at-event-location, mh-seq-msgs): Move here from mh-utils.el.
(mh-iterate-on-messages-in-region, mh-iterate-on-range): Move here
from mh-seq.el.
* mh-alias.el (mh-address-mail-regexp)
(mh-goto-address-find-address-at-point): Move here from mh-utils.el.
(mh-folder-line-matches-show-buffer-p): Move here from mh-e.el.
* mh-buffers.el: Update descriptive text.
* mh-comp.el (mh-note-repl, mh-note-forw, mh-note-dist): Move to new
file mh-scan.el.
(mh-yank-hooks, mh-to-field-choices, mh-position-on-field)
(mh-letter-menu, mh-letter-mode-help-messages)
(mh-letter-buttons-init-flag, mh-letter-mode)
(mh-font-lock-field-data, mh-letter-header-end)
(mh-auto-fill-for-letter, mh-to-field, mh-to-fcc)
(mh-file-is-vcard-p, mh-insert-signature, mh-check-whom)
(mh-insert-letter, mh-extract-from-attribution, mh-yank-cur-msg)
(mh-filter-out-non-text, mh-insert-prefix-string)
(mh-current-fill-prefix, mh-open-line, mh-complete-word)
(mh-folder-expand-at-point, mh-letter-complete-function-alist)
(mh-letter-complete, mh-letter-complete-or-space)
(mh-letter-confirm-address, mh-letter-header-field-at-point)
(mh-letter-next-header-field-or-indent)
(mh-letter-next-header-field, mh-letter-previous-header-field)
(mh-letter-skipped-header-field-p)
(mh-letter-skip-leading-whitespace-in-header-field)
(mh-hidden-header-keymap)
(mh-letter-toggle-header-field-display-button)
(mh-letter-toggle-header-field-display)
(mh-letter-truncate-header-field, mh-letter-mode-map): Move to new
file mh-letter.el.
(mh-letter-mode-map, mh-sent-from-folder, mh-send-args)
(mh-pgp-support-flag, mh-x-mailer-string)
(mh-letter-header-field-regexp): Move to mh-e.el.
(mh-goto-header-field, mh-goto-header-end)
(mh-extract-from-header-value, mh-beginning-of-word): Move to
mh-utils.el.
(mh-insert-header-separator): Move to mh-comp.el.
(mh-display-completion-list-compat): Move to new file mh-compat.el.
* mh-compat.el: New file.
(assoc-string): Move here from mh-acros.el.
(mh-display-completion-list): Move here from mh-comp.el.
* mh-customize.el: Move content into mh-e.el and remove.
* mh-e.el (mh-folder-mode-map, mh-folder-seq-tool-bar-map)
(mh-folder-tool-bar-map, mh-inc-spool-map, mh-letter-mode-map)
(mh-letter-tool-bar-map, mh-search-mode-map, mh-show-mode-map)
(mh-show-seq-tool-bar-map, mh-show-tool-bar-map): All maps now
declared here so that they can be used in docstrings.
(mh-sent-from-folder, mh-sent-from-msg)
(mh-letter-header-field-regexp, mh-pgp-support-flag)
(mh-x-mailer-string): Move here from mh-comp.el.
(mh-folder-line-matches-show-buffer-p): Move to mh-alias.el.
(mh-thread-scan-line-map, mh-thread-scan-line-map-stack): Move here
from mh-seq.el.
(mh-draft-folder, mh-inbox, mh-user-path, mh-current-folder)
(mh-previous-window-config, mh-seen-list, mh-seq-list)
(mh-show-buffer, mh-showing-mode, mh-globals-hash)
(mh-show-folder-buffer, mh-mail-header-separator)
(mh-unseen-seq, mh-previous-seq, mh-page-to-next-msg-flag)
(mh-signature-separator, mh-signature-separator-regexp)
(mh-list-to-string, mh-list-to-string-1): Move here from mh-utils.el.
(mh-index-max-cmdline-args, mh-xargs, mh-quote-for-shell)
(mh-exec-cmd, mh-exec-cmd-error, mh-exec-cmd-daemon)
(mh-exec-cmd-env-daemon, mh-process-daemon, mh-exec-cmd-quiet)
(mh-exec-cmd-output)
(mh-exchange-point-and-mark-preserving-active-mark)
(mh-exec-lib-cmd-output, mh-handle-process-error): Move here from
deprecated file mh-exec.el.
(mh-path): Move here from deprecated file mh-customize.el.
(mh-sys-path, mh-variants, mh-variant-in-use, mh-progs, mh-lib)
(mh-flists-present-flag, mh-variants, mh-variant-mh-info)
(mh-variant-mu-mh-info, mh-variant-nmh-info, mh-file-command-p)
(mh-variant-set-variant, mh-variant-p, mh-profile-component)
(mh-profile-component-value, mh-defface-compat): Move here from
deprecated file mh-init.el.
(mh-goto-next-button, mh-folder-mime-action)
(mh-folder-toggle-mime-part, mh-folder-inline-mime-part)
(mh-folder-save-mime-part, mh-toggle-mime-buttons): Move to to
mh-mime.el.
(mh-scan-format-mh, mh-scan-format-nmh, mh-note-deleted)
(mh-note-refiled, mh-note-cur, mh-scan-good-msg-regexp)
(mh-scan-deleted-msg-regexp, mh-scan-refiled-msg-regexp)
(mh-scan-valid-regexp, mh-scan-cur-msg-number-regexp)
(mh-scan-date-regexp, mh-scan-rcpt-regexp, mh-scan-body-regexp)
(mh-scan-subject-regexp, mh-scan-sent-to-me-sender-regexp)
(mh-scan-cmd-note-width, mh-scan-destination-width)
(mh-scan-date-width, mh-scan-date-flag-width)
(mh-scan-from-mbox-width, mh-scan-from-mbox-sep-width)
(mh-scan-field-destination-offset)
(mh-scan-field-from-start-offset, mh-scan-field-from-end-offset)
(mh-scan-field-subject-start-offset, mh-scan-format)
(mh-msg-num-width-to-column, mh-set-cmd-note): Move to new file
mh-scan.el.
(mh-partial-folder-mode-line-annotation)
(mh-folder-font-lock-keywords, mh-folder-font-lock-subject)
(mh-generate-sequence-font-lock, mh-last-destination)
(mh-last-destination-write, mh-first-msg-num, mh-last-msg-num)
(mh-rmail, mh-nmail, mh-delete-msg, mh-delete-msg-no-motion)
(mh-execute-commands, mh-first-msg, mh-header-display)
(mh-inc-folder, mh-last-msg, mh-next-undeleted-msg)
(mh-folder-from-address, mh-prompt-for-refile-folder)
(mh-refile-msg, mh-refile-or-write-again, mh-quit, mh-page-msg)
(mh-previous-page, mh-previous-undeleted-msg)
(mh-previous-unread-msg, mh-next-button, mh-prev-button)
(mh-reset-threads-and-narrowing, mh-rescan-folder)
(mh-write-msg-to-file, mh-toggle-showing, mh-undo)
(mh-visit-folder, mh-update-sequences, mh-delete-a-msg)
(mh-refile-a-msg, mh-next-msg, mh-next-unread-msg)
(mh-set-scan-mode, mh-undo-msg, mh-make-folder)
(mh-folder-sequence-menu, mh-folder-message-menu)
(mh-folder-folder-menu, mh-remove-xemacs-horizontal-scrollbar)
(mh-write-file-functions-compat, mh-folder-mode)
(mh-restore-desktop-buffer, mh-scan-folder)
(mh-regenerate-headers, mh-generate-new-cmd-note)
(mh-get-new-mail, mh-make-folder-mode-line, mh-goto-cur-msg)
(mh-process-or-undo-commands, mh-process-commands)
(mh-update-unseen, mh-delete-scan-msgs)
(mh-outstanding-commands-p): Move to new file mh-folder.el.
(mh-mapc, mh-colors-available-p, mh-colors-in-use-p)
(mh-make-local-vars, mh-coalesce-msg-list, mh-greaterp)
(mh-lessp): Move to mh-utils.el.
(mh-parse-flist-output-line, mh-folder-size-folder)
(mh-folder-size-flist, mh-folder-size, mh-add-sequence-notation)
(mh-remove-sequence-notation, mh-remove-cur-notation)
(mh-remove-all-notation, mh-delete-seq-locally)
(mh-read-folder-sequences, mh-read-msg-list)
(mh-notate-user-sequences, mh-internal-seqs, mh-internal-seq)
(mh-valid-seq-p, mh-delete-msg-from-seq, mh-catchup)
(mh-delete-a-msg-from-seq, mh-undefine-sequence)
(mh-define-sequence, mh-seq-containing-msg): Move to mh-seq.el.
(mh-xemacs-flag)
(mh-customize, mh-e, mh-alias, mh-folder, mh-folder-selection)
(mh-identity, mh-inc, mh-junk, mh-letter, mh-ranges)
(mh-scan-line-formats, mh-search, mh-sending-mail, mh-sequences)
(mh-show, mh-speedbar, mh-thread, mh-tool-bar, mh-hooks)
(mh-faces, mh-alias-completion-ignore-case-flag)
(mh-alias-expand-aliases-flag, mh-alias-flash-on-comma)
(mh-alias-insert-file, mh-alias-insertion-location)
(mh-alias-local-users, mh-alias-local-users-prefix)
(mh-alias-passwd-gecos-comma-separator-flag)
(mh-new-messages-folders, mh-ticked-messages-folders)
(mh-large-folder, mh-recenter-summary-flag)
(mh-recursive-folders-flag, mh-sortm-args)
(mh-default-folder-for-message-function, mh-default-folder-list)
(mh-default-folder-must-exist-flag, mh-default-folder-prefix)
(mh-identity-list, mh-auto-fields-list)
(mh-auto-fields-prompt-flag, mh-identity-default)
(mh-identity-handlers, mh-inc-prog, mh-inc-spool-list)
(mh-junk-choice, mh-junk-function-alist, mh-junk-choose)
(mh-junk-background, mh-junk-disposition, mh-junk-program)
(mh-compose-insertion, mh-compose-skipped-header-fields)
(mh-compose-space-does-completion-flag)
(mh-delete-yanked-msg-window-flag)
(mh-extract-from-attribution-verb, mh-ins-buf-prefix)
(mh-letter-complete-function, mh-letter-fill-column)
(mh-mml-method-default, mh-signature-file-name)
(mh-signature-separator-flag, mh-x-face-file, mh-yank-behavior)
(mh-interpret-number-as-range-flag, mh-adaptive-cmd-note-flag)
(mh-scan-format-file-check, mh-scan-format-file)
(mh-adaptive-cmd-note-flag-check, mh-scan-prog)
(mh-search-program, mh-compose-forward-as-mime-flag)
(mh-compose-letter-function, mh-compose-prompt-flag)
(mh-forward-subject-format, mh-insert-x-mailer-flag)
(mh-redist-full-contents-flag, mh-reply-default-reply-to)
(mh-reply-show-message-flag, mh-refile-preserves-sequences-flag)
(mh-tick-seq, mh-update-sequences-after-mh-show-flag)
(mh-bury-show-buffer-flag, mh-clean-message-header-flag)
(mh-decode-mime-flag, mh-display-buttons-for-alternatives-flag)
(mh-display-buttons-for-inline-parts-flag)
(mh-do-not-confirm-flag, mh-fetch-x-image-url)
(mh-graphical-smileys-flag, mh-graphical-emphasis-flag)
(mh-highlight-citation-style)
(mh-invisible-header-fields-internal)
(mh-delay-invisible-header-generation-flag)
(mh-invisible-header-fields, mh-invisible-header-fields-default)
(mh-invisible-header-fields-compiled, mh-invisible-headers)
(mh-lpr-command-format, mh-max-inline-image-height)
(mh-max-inline-image-width, mh-mhl-format-file)
(mh-mime-save-parts-default-directory, mh-print-background-flag)
(mh-show-maximum-size, mh-show-use-goto-addr-flag)
(mh-show-use-xface-flag, mh-store-default-directory)
(mh-summary-height, mh-speed-update-interval)
(mh-show-threads-flag, mh-tool-bar-search-function)
(mh-after-commands-processed-hook, mh-alias-reloaded-hook)
(mh-before-commands-processed-hook, mh-before-quit-hook)
(mh-before-send-letter-hook, mh-delete-msg-hook)
(mh-find-path-hook, mh-folder-mode-hook, mh-forward-hook)
(mh-inc-folder-hook, mh-insert-signature-hook)
(mh-kill-folder-suppress-prompt-hooks, mh-letter-mode-hook)
(mh-mh-to-mime-hook, mh-search-mode-hook, mh-quit-hook)
(mh-refile-msg-hook, mh-show-hook, mh-show-mode-hook)
(mh-unseen-updated-hook, mh-min-colors-defined-flag)
(mh-folder-address, mh-folder-body)
(mh-folder-cur-msg-number, mh-folder-date, mh-folder-deleted)
(mh-folder-followup, mh-folder-msg-number, mh-folder-refiled)
(mh-folder-sent-to-me-hint, mh-folder-sent-to-me-sender)
(mh-folder-subject, mh-folder-tick, mh-folder-to)
(mh-search-folder, mh-letter-header-field, mh-show-cc)
(mh-show-date, mh-show-from, mh-show-header, mh-show-pgg-bad)
(mh-show-pgg-good, mh-show-pgg-unknown, mh-show-signature)
(mh-show-subject, mh-show-to, mh-show-xface, mh-speedbar-folder)
(mh-speedbar-folder-with-unseen-messages)
(mh-speedbar-selected-folder)
(mh-speedbar-selected-folder-with-unseen-messages): Move here from
deprecated file mh-customize.el.
* mh-exec.el: Move content into mh-e.el and remove.
* mh-folder.el: New file. Contains mh-folder-mode from mh-e.el
* mh-funcs.el (mh-note-copied, mh-note-printed): Move to new file
mh-scan.el.
(mh-ephem-message, mh-help, mh-prefix-help): Move to mh-utils.el.
* mh-gnus.el (mm-uu-dissect-text-parts): Add.
(mh-mail-abbrev-make-syntax-table): Move to mh-utils.el and rename to
mail-abbrev-make-syntax-table.
* mh-identity.el (mh-identity-menu): New variable for existing menu.
(mh-identity-make-menu-no-autoload): New alias for
mh-identity-make-menu which can be called from mh-e.el.
(mh-identity-list-set): Move to mh-e.el.
(mh-identity-add-menu): New function
(mh-insert-identity): Add optional argument maybe-insert so that local
variable mh-identity-local does not have to be visible.
(mh-identity-handler-default):
* mh-inc.el (mh-inc-spool-map): Move declaration to mh-e.el (with rest
of keymaps). Update key binding for ? to call mh-help with help
messages in new argument.
(mh-inc-spool-make-no-autoload): New alias for mh-inc-spool-make which
can be called from mh-e.el.
(mh-inc-spool-list-set): Simplify update of mh-inc-spool-map-help.
* mh-init.el: Move content into mh-e.el and remove.
* mh-junk.el: Update requires, untabify, and add mh-autoload cookies.
* mh-letter.el: New file. Contains mh-letter-mode from mh-comp.el.
* mh-limit.el: New file. Contains display limit commands from
mh-mime.el.
* mh-mime.el: Rearrange for consistency with other files.
(mh-buffer-data, mh-mm-inline-media-tests): Move here from
mh-utils.el.
(mh-folder-inline-mime-part, mh-folder-save-mime-part)
(mh-folder-toggle-mime-part, mh-toggle-mime-buttons)
(mh-goto-next-button): Move here from mh-e.el.
* mh-print.el: Rearrange for consistency with other files.
* mh-scan.el: New file. Contains scan line constants and utilities
from XXX, mh-funcs, mh-utils.el.
* mh-search.el: Rearrange for consistency with other files.
(mh-search-mode-map): Drop C-c C-f {dr} bindings since these fields
which don't exist in the saved header. Replace C-c C-f f with C-c C-f
m per mail-mode consistency.
(mh-search-mode): Use mh-set-help instead of setting mh-help-messages.
* mh-seq.el (mh-thread-message, mh-thread-container)
(mh-thread-id-hash, mh-thread-subject-hash, mh-thread-id-table)
(mh-thread-id-index-map, mh-thread-index-id-map)
(mh-thread-scan-line-map, mh-thread-scan-line-map-stack)
(mh-thread-subject-container-hash, mh-thread-duplicates)
(mh-thread-history, mh-thread-body-width)
(mh-thread-find-msg-subject mh-thread-initialize-hash)
(mh-thread-initialize, mh-thread-id-container)
(mh-thread-remove-parent-link, mh-thread-add-link)
(mh-thread-ancestor-p, mh-thread-get-message-container)
(mh-thread-get-message, mh-thread-canonicalize-id)
(mh-thread-prune-subject, mh-thread-container-subject)
(mh-thread-rewind-pruning, mh-thread-prune-containers)
(mh-thread-sort-containers, mh-thread-group-by-subject)
(mh-thread-process-in-reply-to, mh-thread-set-tables)
(mh-thread-update-id-index-maps, mh-thread-generate)
(mh-thread-inc, mh-thread-generate-scan-lines)
(mh-thread-parse-scan-line, mh-thread-update-scan-line-map)
(mh-thread-add-spaces, mh-thread-print-scan-lines)
(mh-thread-folder, mh-toggle-threads, mh-thread-forget-message)
(mh-thread-current-indentation-level, mh-thread-next-sibling)
(mh-thread-previous-sibling, mh-thread-immediate-ancestor)
(mh-thread-ancestor, mh-thread-find-children)
(mh-message-id-regexp, mh-thread-delete, mh-thread-refile): Move to
new file mh-thread.el.
(mh-subject-to-sequence, mh-subject-to-sequence-unthreaded)
(mh-subject-to-sequence-threaded, mh-edit-pick-expr)
(mh-pick-args-list, mh-narrow-to-subject, mh-narrow-to-from)
(mh-narrow-to-cc, mh-narrow-to-to, mh-narrow-to-header-field)
(mh-current-message-header-field, mh-narrow-to-range)
(mh-delete-subject, mh-delete-subject-or-thread): Move to new file
mh-limit.el.
(mh-iterate-on-messages-in-region, mh-iterate-on-range): Move to
mh-acros.el.
(mh-internal-seqs, mh-catchup, mh-delete-msg-from-seq)
(mh-internal-seq, mh-valid-seq-p, mh-seq-containing-msg)
(mh-define-sequence, mh-undefine-sequence)
(mh-delete-a-msg-from-seq, mh-delete-seq-locally)
(mh-folder-size, mh-folder-size-flist, mh-folder-size-folder)
(mh-parse-flist-output-line, mh-read-folder-sequences)
(mh-read-msg-list, mh-notate-user-sequences)
(mh-remove-cur-notation, mh-add-sequence-notation)
(mh-remove-sequence-notation, mh-remove-all-notation): Move here from
mh-e.el.
(mh-make-seq, mh-seq-name, mh-find-seq, mh-seq-to-msgs)
(mh-add-msgs-to-seq, mh-notate): Move here from mh-utils.el.
* mh-show.el: New file. Contains mh-show-mode from mh-utils.el.
* mh-speed.el: Rearrange for consistency with other files.
* mh-thread.el: New file. Contains threading code from mh-seq.el.
* mh-tool-bar.el: New file. Contains tool bar creation code from
deprecated file mh-customize.el.
* mh-utils.el (recursive-load-depth-limit): Remove setting. No longer
needed.
(mh-scan-msg-number-regexp, mh-scan-msg-overflow-regexp)
(mh-scan-msg-format-regexp, mh-scan-msg-format-string)
(mh-scan-msg-search-regexp, mh-cmd-note, mh-note-seq)
(mh-update-scan-format, mh-msg-num-width): Move to new file
mh-scan.el.
(mh-show-buffer-mode-line-buffer-id, mh-letter-header-font-lock)
(mh-header-field-font-lock, mh-header-to-font-lock)
(mh-header-cc-font-lock, mh-header-subject-font-lock)
(mh-show-font-lock-keywords)
(mh-show-font-lock-keywords-with-cite)
(mh-show-font-lock-fontify-region)
(mh-gnus-article-highlight-citation, mh-showing-with-headers)
(mh-start-of-uncleaned-message, mh-invalidate-show-buffer)
(mh-unvisit-file, mh-defun-show-buffer, mh-show-mode-map)
(mh-show-sequence-menu, mh-show-message-menu)
(mh-show-folder-menu, mh-show-mode, mh-show-addr)
(mh-maybe-show, mh-show, mh-show-msg, mh-show-unquote-From)
(mh-msg-folder, mh-display-msg, mh-clean-msg-header): Move to new file
mh-show.el.
(mh-mail-header-separator, mh-signature-separator-regexp)
(mh-signature-separator, mh-globals-hash, mh-user-path)
(mh-draft-folder, mh-unseen-seq, mh-previous-seq, mh-inbox)
(mh-previous-window-config, mh-current-folder mh-show-buffer)
(mh-showing-mode, mh-show-mode-map, mh-show-folder-buffer)
(mh-showing-mode, mh-seq-list, mh-seen-list, mh-summary-height)
(mh-list-to-string, mh-list-to-string-1): Move to mh-e.el.
(mh-buffer-data, mh-mm-inline-media-tests): Move to mh-mime.el.
(mh-address-mail-regexp, mh-goto-address-find-address-at-point): Move
to mh-alias.el.
(mh-letter-font-lock-keywords): Move to new file mh-letter.el.
(mh-folder-filename, mh-msg-count, mh-recenter, mh-msg-filename)
(mh-show-mouse, mh-modify, mh-goto-msg, mh-set-folder-modified-p):
Move to new file mh-folder.el.
(with-mh-folder-updating, mh-in-show-buffer)
(mh-do-at-event-location, mh-seq-msgs): Moved to mh-acros.el.
(mh-make-seq, mh-seq-name, mh-notate, mh-find-seq)
(mh-seq-to-msgs, mh-add-msgs-to-seq, mh-canonicalize-sequence): Moved
to mh-seq.el.
(mh-show-xface-function, mh-uncompface-executable, mh-face-to-png)
(mh-uncompface, mh-icontopbm, mh-face-foreground-compat)
(mh-face-background-compat, mh-face-display-function)
(mh-show-xface, mh-picon-directory-list)
(mh-picon-existing-directory-list)
(mh-picon-cache, mh-picon-image-types)
(mh-picon-set-directory-list, mh-picon-get-image)
(mh-picon-file-contents, mh-picon-generate-path)
(mh-x-image-cache-directory, mh-x-image-scaling-function)
(mh-wget-executable, mh-wget-choice, mh-wget-option)
(mh-x-image-temp-file, mh-x-image-url, mh-x-image-marker)
(mh-x-image-url-cache-file, mh-x-image-scale-with-pnm)
(mh-x-image-scale-with-convert)
(url-unreserved-chars, url-hexify-string)
(mh-x-image-url-cache-canonicalize)
(mh-x-image-set-download-state, mh-x-image-get-download-state)
(mh-x-image-url-fetch-image, mh-x-image-display)
(mh-x-image-scale-and-display, mh-x-image-url-sane-p)
(mh-x-image-url-display): Move to new file mh-xface.el.
(mh-logo-display): Call mh-image-load-path.
(mh-find-path-run, mh-find-path): Move here from deprecated file
mh-init.el.
(mh-help-messages): Now an alist of modes to an alist of messages.
(mh-set-help): New function used to set mh-help-messages
(mh-help): Adjust for new format of mh-help-messages. Add
help-messages argument.
(mh-prefix-help): Refactor to use mh-help.
(mh-coalesce-msg-list, mh-greaterp, mh-lessp): Move here from mh-e.el.
(mh-clear-sub-folders-cache): New function added to avoid exposing
mh-sub-folders-cache variable.
* mh-xface.el: New file. Contains X-Face and Face header field display
routines from mh-utils.el.
author | Bill Wohler <wohler@newt.com> |
---|---|
date | Sun, 29 Jan 2006 19:34:57 +0000 |
parents | |
children | 4bd450a8dbe2 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lisp/mh-e/mh-letter.el Sun Jan 29 19:34:57 2006 +0000 @@ -0,0 +1,1040 @@ +;;; mh-letter.el --- MH-Letter mode + +;; Copyright (C) 1993, 1995, 1997, +;; 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +;; Author: Bill Wohler <wohler@newt.com> +;; Maintainer: Bill Wohler <wohler@newt.com> +;; Keywords: mail +;; See: mh-e.el + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; Mode for composing and sending a draft message. + +;; Functions that would ordinarily be in here that are needed by +;; mh-show.el should be placed in the Message Utilities section in +;; mh-utils.el. That will help prevent the loading of this file until +;; a message is actually composed. + +;;; Change Log: + +;;; Code: + +(require 'mh-e) + +(require 'gnus-util) + +;; Dynamically-created function not found in mh-loaddefs.el. +(autoload 'mh-tool-bar-letter-buttons-init "mh-tool-bar") + +(autoload 'mml-insert-tag "mml") + +;;; Variables + +(defvar mh-letter-complete-function-alist + '((bcc . mh-alias-letter-expand-alias) + (cc . mh-alias-letter-expand-alias) + (dcc . mh-alias-letter-expand-alias) + (fcc . mh-folder-expand-at-point) + (from . mh-alias-letter-expand-alias) + (mail-followup-to . mh-alias-letter-expand-alias) + (mail-reply-to . mh-alias-letter-expand-alias) + (reply-to . mh-alias-letter-expand-alias) + (to . mh-alias-letter-expand-alias)) + "Alist of header fields and completion functions to use.") + +(defvar mh-hidden-header-keymap + (let ((map (make-sparse-keymap))) + (mh-do-in-gnu-emacs + (define-key map [mouse-2] 'mh-letter-toggle-header-field-display-button)) + (mh-do-in-xemacs + (define-key map '(button2) + 'mh-letter-toggle-header-field-display-button)) + map)) + +(defvar mh-yank-hooks nil + "Obsolete hook for modifying a citation just inserted in the mail buffer. + +Each hook function can find the citation between point and mark. +And each hook function should leave point and mark around the +citation text as modified. + +This is a normal hook, misnamed for historical reasons. It is +semi-obsolete and is only used if `mail-citation-hook' is nil.") + + + +;;; Letter Menu + +(eval-when-compile (defvar mh-letter-menu nil)) +(easy-menu-define + mh-letter-menu mh-letter-mode-map "Menu for MH-E letter mode." + '("Letter" + ["Send This Draft" mh-send-letter t] + ["Split Current Line" mh-open-line t] + ["Check Recipient" mh-check-whom t] + ["Yank Current Message" mh-yank-cur-msg t] + ["Insert a Message..." mh-insert-letter t] + ["Insert Signature" mh-insert-signature t] + ("Encrypt/Sign Message" + ["Sign Message" + mh-mml-secure-message-sign mh-pgp-support-flag] + ["Encrypt Message" + mh-mml-secure-message-encrypt mh-pgp-support-flag] + ["Sign+Encrypt Message" + mh-mml-secure-message-signencrypt mh-pgp-support-flag] + ["Disable Security" + mh-mml-unsecure-message mh-pgp-support-flag] + "--" + "Security Method" + ["PGP (MIME)" (setq mh-mml-method-default "pgpmime") + :style radio + :selected (equal mh-mml-method-default "pgpmime")] + ["PGP" (setq mh-mml-method-default "pgp") + :style radio + :selected (equal mh-mml-method-default "pgp")] + ["S/MIME" (setq mh-mml-method-default "smime") + :style radio + :selected (equal mh-mml-method-default "smime")] + "--" + ["Save Method as Default" + (customize-save-variable 'mh-mml-method-default mh-mml-method-default) t] + ) + ["Compose Insertion..." mh-compose-insertion t] + ["Compose Compressed tar (MH)..." + mh-mh-compose-external-compressed-tar t] + ["Compose Get File (MH)..." mh-mh-compose-anon-ftp t] + ["Compose Forward..." mh-compose-forward t] + ;; The next two will have to be merged. But I also need to make sure the + ;; user can't mix tags of both types. + ["Pull in All Compositions (MH)" + mh-mh-to-mime (mh-mh-directive-present-p)] + ["Pull in All Compositions (MML)" + mh-mml-to-mime (mh-mml-tag-present-p)] + ["Revert to Non-MIME Edit (MH)" + mh-mh-to-mime-undo (equal mh-compose-insertion 'mh)] + ["Kill This Draft" mh-fully-kill-draft t])) + + + +;;; MH-Letter Keys + +;; If this changes, modify mh-letter-mode-help-messages accordingly, above. +(gnus-define-keys mh-letter-mode-map + " " mh-letter-complete-or-space + "," mh-letter-confirm-address + "\C-c?" mh-help + "\C-c\C-\\" mh-fully-kill-draft ;if no C-q + "\C-c\C-^" mh-insert-signature ;if no C-s + "\C-c\C-c" mh-send-letter + "\C-c\C-d" mh-insert-identity + "\C-c\C-e" mh-mh-to-mime + "\C-c\C-f\C-a" mh-to-field + "\C-c\C-f\C-b" mh-to-field + "\C-c\C-f\C-c" mh-to-field + "\C-c\C-f\C-d" mh-to-field + "\C-c\C-f\C-f" mh-to-fcc + "\C-c\C-f\C-l" mh-to-field + "\C-c\C-f\C-m" mh-to-field + "\C-c\C-f\C-r" mh-to-field + "\C-c\C-f\C-s" mh-to-field + "\C-c\C-f\C-t" mh-to-field + "\C-c\C-fa" mh-to-field + "\C-c\C-fb" mh-to-field + "\C-c\C-fc" mh-to-field + "\C-c\C-fd" mh-to-field + "\C-c\C-ff" mh-to-fcc + "\C-c\C-fl" mh-to-field + "\C-c\C-fm" mh-to-field + "\C-c\C-fr" mh-to-field + "\C-c\C-fs" mh-to-field + "\C-c\C-ft" mh-to-field + "\C-c\C-i" mh-insert-letter + "\C-c\C-m\C-e" mh-mml-secure-message-encrypt + "\C-c\C-m\C-f" mh-compose-forward + "\C-c\C-m\C-g" mh-mh-compose-anon-ftp + "\C-c\C-m\C-i" mh-compose-insertion + "\C-c\C-m\C-m" mh-mml-to-mime + "\C-c\C-m\C-n" mh-mml-unsecure-message + "\C-c\C-m\C-s" mh-mml-secure-message-sign + "\C-c\C-m\C-t" mh-mh-compose-external-compressed-tar + "\C-c\C-m\C-u" mh-mh-to-mime-undo + "\C-c\C-m\C-x" mh-mh-compose-external-type + "\C-c\C-mee" mh-mml-secure-message-encrypt + "\C-c\C-mes" mh-mml-secure-message-signencrypt + "\C-c\C-mf" mh-compose-forward + "\C-c\C-mg" mh-mh-compose-anon-ftp + "\C-c\C-mi" mh-compose-insertion + "\C-c\C-mm" mh-mml-to-mime + "\C-c\C-mn" mh-mml-unsecure-message + "\C-c\C-mse" mh-mml-secure-message-signencrypt + "\C-c\C-mss" mh-mml-secure-message-sign + "\C-c\C-mt" mh-mh-compose-external-compressed-tar + "\C-c\C-mu" mh-mh-to-mime-undo + "\C-c\C-mx" mh-mh-compose-external-type + "\C-c\C-o" mh-open-line + "\C-c\C-q" mh-fully-kill-draft + "\C-c\C-s" mh-insert-signature + "\C-c\C-t" mh-letter-toggle-header-field-display + "\C-c\C-w" mh-check-whom + "\C-c\C-y" mh-yank-cur-msg + "\C-c\M-d" mh-insert-auto-fields + "\M-\t" mh-letter-complete + "\t" mh-letter-next-header-field-or-indent + [backtab] mh-letter-previous-header-field) + +;; "C-c /" prefix is used in mh-letter-mode by pgp.el and mailcrypt.el. + + + +;;; MH-Letter Help Messages + +;; Group messages logically, more or less. +(defvar mh-letter-mode-help-messages + '((nil + "Send letter: \\[mh-send-letter] " + "Open line: \\[mh-open-line]\n" + "Kill letter: \\[mh-fully-kill-draft] " + "Check recipients: \\[mh-check-whom]\n\n" + "Insert:\n" + " Current message: \\[mh-yank-cur-msg]\n" + " Attachment: \\[mh-compose-insertion]\n" + " Message to forward: \\[mh-compose-forward]\n" + " Signature: \\[mh-insert-signature]\n\n" + "Security:\n" + " Encrypt message: \\[mh-mml-secure-message-encrypt]\n" + " Sign message: \\[mh-mml-secure-message-sign]\n" + " Sign+Encrypt message: \\[mh-mml-secure-message-signencrypt]")) + "Key binding cheat sheet. + +This is an associative array which is used to show the most +common commands. The key is a prefix char. The value is one or +more strings which are concatenated together and displayed in the +minibuffer if ? is pressed after the prefix character. The +special key nil is used to display the non-prefixed commands. + +The substitutions described in `substitute-command-keys' are +performed as well.") + + + +;;; MH-Letter Font Lock + +(defvar mh-letter-font-lock-keywords + `(,@(mh-show-font-lock-keywords-with-cite) + (mh-font-lock-field-data + (1 'mh-letter-header-field prepend t))) + "Additional expressions to highlight in MH-Letter buffers.") + +(defun mh-font-lock-field-data (limit) + "Find header field region between point and LIMIT." + (and (< (point) (mh-letter-header-end)) + (< (point) limit) + (let ((end (min limit (mh-letter-header-end))) + (point (point)) + data-end data-begin field) + (end-of-line) + (setq data-end (if (re-search-forward "^[^ \t]" end t) + (match-beginning 0) + end)) + (goto-char (1- data-end)) + (if (not (re-search-backward "\\(^[^ \t][^:]*\\):[ \t]*" nil t)) + (setq data-begin (point-min)) + (setq data-begin (match-end 0)) + (setq field (match-string 1))) + (setq data-begin (max point data-begin)) + (goto-char (if (equal point data-end) (1+ data-end) data-end)) + (cond ((and field (mh-letter-skipped-header-field-p field)) + (set-match-data nil) + nil) + (t (set-match-data + (list data-begin data-end data-begin data-end)) + t))))) + +(defun mh-letter-header-end () + "Find the end of the message header. +This function is to be used only for font locking. It works by +searching for `mh-mail-header-separator' in the buffer." + (save-excursion + (goto-char (point-min)) + (cond ((equal mh-mail-header-separator "") (point-min)) + ((search-forward (format "\n%s\n" mh-mail-header-separator) nil t) + (line-beginning-position 0)) + (t (point-min))))) + + + +;;; MH-Letter Mode + +(defvar mh-letter-buttons-init-flag nil) + +;; Shush compiler. +(eval-when-compile (mh-do-in-xemacs (defvar font-lock-defaults))) + +;; Ensure new buffers won't get this mode if default-major-mode is nil. +(put 'mh-letter-mode 'mode-class 'special) + +;;;###mh-autoload +(define-derived-mode mh-letter-mode mail-mode "MH-Letter" + "Mode for composing letters in MH-E\\<mh-letter-mode-map>. + +When you have finished composing, type \\[mh-send-letter] to send +the message using the MH mail handling system. + +There are two types of tags used by MH-E when composing MIME +messages: MML and MH. The option `mh-compose-insertion' controls +what type of tags are inserted by MH-E commands. These tags can +be converted to MIME body parts by running \\[mh-mh-to-mime] for +MH-style directives or \\[mh-mml-to-mime] for MML tags. + +Options that control this mode can be changed with +\\[customize-group]; specify the \"mh-compose\" group. + +When a message is composed, the hooks `text-mode-hook', +`mail-mode-hook', and `mh-letter-mode-hook' are run (in that +order). + +\\{mh-letter-mode-map}" + (mh-find-path) + (make-local-variable 'mh-send-args) + (make-local-variable 'mh-annotate-char) + (make-local-variable 'mh-annotate-field) + (make-local-variable 'mh-previous-window-config) + (make-local-variable 'mh-sent-from-folder) + (make-local-variable 'mh-sent-from-msg) + (mh-do-in-gnu-emacs + (unless mh-letter-buttons-init-flag + (mh-tool-bar-letter-buttons-init) + (setq mh-letter-buttons-init-flag t))) + ;; Set the local value of mh-mail-header-separator according to what is + ;; present in the buffer... + (set (make-local-variable 'mh-mail-header-separator) + (save-excursion + (goto-char (mh-mail-header-end)) + (buffer-substring-no-properties (point) (line-end-position)))) + (make-local-variable 'mail-header-separator) + (setq mail-header-separator mh-mail-header-separator) ;override sendmail.el + (mh-set-help mh-letter-mode-help-messages) + (setq buffer-invisibility-spec '((vanish . t) t)) + (set (make-local-variable 'line-move-ignore-invisible) t) + + ;; Enable undo since a show-mode buffer might have been reused. + (buffer-enable-undo) + (set (make-local-variable 'tool-bar-map) mh-letter-tool-bar-map) + (mh-funcall-if-exists mh-tool-bar-init :letter) + (make-local-variable 'font-lock-defaults) + (cond + ((or (equal mh-highlight-citation-style 'font-lock) + (equal mh-highlight-citation-style 'gnus)) + ;; Let's use font-lock even if gnus is used in show-mode. The reason + ;; is that gnus uses static text properties which are not appropriate + ;; for a buffer that will be edited. So the choice here is either fontify + ;; the citations and header... + (setq font-lock-defaults '(mh-letter-font-lock-keywords t))) + (t + ;; ...or the header only + (setq font-lock-defaults '((mh-show-font-lock-keywords) t)))) + (easy-menu-add mh-letter-menu) + (setq fill-column mh-letter-fill-column) + ;; If text-mode-hook turned on auto-fill, tune it for messages + (when auto-fill-function + (make-local-variable 'auto-fill-function) + (setq auto-fill-function 'mh-auto-fill-for-letter))) + + + +;;; MH-Letter Commands + +;; Alphabetical. +;; See also mh-comp.el and mh-mime.el. + +(defun mh-check-whom () + "Verify recipients, showing expansion of any aliases. + +This command expands aliases so you can check the actual address(es) +in the alias. A new buffer named \"*MH-E Recipients*\" is created with +the output of \"whom\"." + (interactive) + (let ((file-name buffer-file-name)) + (save-buffer) + (message "Checking recipients...") + (mh-in-show-buffer (mh-recipients-buffer) + (bury-buffer (current-buffer)) + (erase-buffer) + (mh-exec-cmd-output "whom" t file-name)) + (message "Checking recipients...done"))) + +(defun mh-insert-letter (folder message verbatim) + "Insert a message. + +This command prompts you for the FOLDER and MESSAGE number, which +defaults to the current message in that folder. It then inserts +the message, indented by `mh-ins-buf-prefix' (\"> \") unless +`mh-yank-behavior' is set to one of the supercite flavors in +which case supercite is used to format the message. Certain +undesirable header fields (see +`mh-invisible-header-fields-compiled') are removed before +insertion. + +If given a prefix argument VERBATIM, the header is left intact, the +message is not indented, and \"> \" is not inserted before each line. +This command leaves the mark before the letter and point after it." + (interactive + (let* ((folder + (mh-prompt-for-folder "Message from" + mh-sent-from-folder nil)) + (default + (if (and (equal folder mh-sent-from-folder) + (numberp mh-sent-from-msg)) + mh-sent-from-msg + (nth 0 (mh-translate-range folder "cur")))) + (message + (read-string (concat "Message number" + (or (and default + (format " (default %d): " default)) + ": "))))) + (list folder message current-prefix-arg))) + (save-restriction + (narrow-to-region (point) (point)) + (let ((start (point-min))) + (if (and (equal message "") (numberp mh-sent-from-msg)) + (setq message (int-to-string mh-sent-from-msg))) + (insert-file-contents + (expand-file-name message (mh-expand-file-name folder))) + (when (not verbatim) + (mh-clean-msg-header start mh-invisible-header-fields-compiled nil) + (goto-char (point-max)) ;Needed for sc-cite-original + (push-mark) ;Needed for sc-cite-original + (goto-char (point-min)) ;Needed for sc-cite-original + (mh-insert-prefix-string mh-ins-buf-prefix))))) + +;;;###mh-autoload +(defun mh-insert-signature (&optional file) + "Insert signature in message. + +This command inserts your signature at the current cursor location. + +By default, the text of your signature is taken from the file +\"~/.signature\". You can read from other sources by changing the +option `mh-signature-file-name'. + +A signature separator (\"-- \") will be added if the signature block +does not contain one and `mh-signature-separator-flag' is on. + +The hook `mh-insert-signature-hook' is run after the signature is +inserted. Hook functions may access the actual name of the file or the +function used to insert the signature with `mh-signature-file-name'. + +The signature can also be inserted using Identities (see +`mh-identity-list'). + +In a program, you can pass in a signature FILE." + (interactive) + (save-excursion + (insert "\n") + (let ((mh-signature-file-name (or file mh-signature-file-name)) + (mh-mh-p (mh-mh-directive-present-p)) + (mh-mml-p (mh-mml-tag-present-p))) + (save-restriction + (narrow-to-region (point) (point)) + (cond + ((mh-file-is-vcard-p mh-signature-file-name) + (if (equal mh-compose-insertion 'mml) + (insert "<#part type=\"text/x-vcard\" filename=\"" + mh-signature-file-name + "\" disposition=inline description=VCard>\n<#/part>") + (insert "#text/x-vcard; name=\"" + (file-name-nondirectory mh-signature-file-name) + "\" [VCard] " (expand-file-name mh-signature-file-name)))) + (t + (cond + (mh-mh-p + (insert "#\n" "Content-Description: Signature\n")) + (mh-mml-p + (mml-insert-tag 'part 'type "text/plain" 'disposition "inline" + 'description "Signature"))) + (cond ((null mh-signature-file-name)) + ((and (stringp mh-signature-file-name) + (file-readable-p mh-signature-file-name)) + (insert-file-contents mh-signature-file-name)) + ((functionp mh-signature-file-name) + (funcall mh-signature-file-name))))) + (save-restriction + (widen) + (run-hooks 'mh-insert-signature-hook)) + (goto-char (point-min)) + (when (and (not (mh-file-is-vcard-p mh-signature-file-name)) + mh-signature-separator-flag + (> (point-max) (point-min)) + (not (mh-signature-separator-p))) + (cond (mh-mh-p + (forward-line 2)) + (mh-mml-p + (forward-line 1))) + (insert mh-signature-separator)) + (if (not (> (point-max) (point-min))) + (message "No signature found"))))) + (force-mode-line-update)) + +(defun mh-letter-complete (arg) + "Perform completion on header field or word preceding point. + +If the field contains addresses (for example, \"To:\" or \"Cc:\") +or folders (for example, \"Fcc:\") then this command will provide +alias completion. In the body of the message, this command runs +`mh-letter-complete-function' instead, which is set to +`ispell-complete-word' by default. This command takes a prefix +argument ARG that is passed to the +`mh-letter-complete-function'." + (interactive "P") + (let ((func nil)) + (cond ((not (mh-in-header-p)) + (funcall mh-letter-complete-function arg)) + ((setq func (cdr (assoc (mh-letter-header-field-at-point) + mh-letter-complete-function-alist))) + (funcall func)) + (t (funcall mh-letter-complete-function arg))))) + +(defun mh-letter-complete-or-space (arg) + "Perform completion or insert space. + +Turn on the option `mh-compose-space-does-completion-flag' to use +this command to perform completion in the header. Otherwise, a +space is inserted; use a prefix argument ARG to specify more than +one space." + (interactive "p") + (let ((func nil) + (end-of-prev (save-excursion + (goto-char (mh-beginning-of-word)) + (mh-beginning-of-word -1)))) + (cond ((not mh-compose-space-does-completion-flag) + (self-insert-command arg)) + ((not (mh-in-header-p)) (self-insert-command arg)) + ((> (point) end-of-prev) (self-insert-command arg)) + ((setq func (cdr (assoc (mh-letter-header-field-at-point) + mh-letter-complete-function-alist))) + (funcall func)) + (t (self-insert-command arg))))) + +(defun mh-letter-confirm-address () + "Flash alias expansion. + +Addresses are separated by a comma\; when you press the comma, +this command flashes the alias expansion in the minibuffer if +`mh-alias-flash-on-comma' is turned on." + (interactive) + (cond ((not (mh-in-header-p)) (self-insert-command 1)) + ((eq (cdr (assoc (mh-letter-header-field-at-point) + mh-letter-complete-function-alist)) + 'mh-alias-letter-expand-alias) + (mh-alias-reload-maybe) + (mh-alias-minibuffer-confirm-address)) + (t (self-insert-command 1)))) + +(defun mh-letter-next-header-field-or-indent (arg) + "Cycle to next field. + +Within the header of the message, this command moves between +fields that are highlighted with the face +`mh-letter-header-field', skipping those fields listed in +`mh-compose-skipped-header-fields'. After the last field, this +command then moves point to the message body before cycling back +to the first field. If point is already past the first line of +the message body, then this command indents by calling +`indent-relative' with the given prefix argument ARG." + (interactive "P") + (let ((header-end (save-excursion + (goto-char (mh-mail-header-end)) + (forward-line) + (point)))) + (if (> (point) header-end) + (indent-relative arg) + (mh-letter-next-header-field)))) + +(defun mh-letter-previous-header-field () + "Cycle to the previous header field. + +This command moves backwards between the fields and cycles to the +body of the message after the first field. Unlike the command +\\[mh-letter-next-header-field-or-indent], it will always take +point to the last field from anywhere in the body." + (interactive) + (let ((header-end (mh-mail-header-end))) + (if (>= (point) header-end) + (goto-char header-end) + (mh-header-field-beginning)) + (cond ((re-search-backward mh-letter-header-field-regexp nil t) + (if (mh-letter-skipped-header-field-p (match-string 1)) + (mh-letter-previous-header-field) + (goto-char (match-end 0)) + (mh-letter-skip-leading-whitespace-in-header-field))) + (t (goto-char header-end) + (forward-line))))) + +;;;###mh-autoload +(defun mh-letter-toggle-header-field-display (arg) + "Toggle display of header field at point. + +Use this command to display truncated header fields. This command +is a toggle so entering it again will hide the field. This +command takes a prefix argument ARG: if negative then the field +is hidden, if positive then the field is displayed." + (interactive (list nil)) + (when (and (mh-in-header-p) + (progn + (end-of-line) + (re-search-backward mh-letter-header-field-regexp nil t))) + (let ((buffer-read-only nil) + (modified-flag (buffer-modified-p)) + (begin (point)) + end) + (end-of-line) + (setq end (1- (if (re-search-forward "^[^ \t]" nil t) + (match-beginning 0) + (point-max)))) + (goto-char begin) + ;; Make it clickable... + (add-text-properties begin end `(keymap ,mh-hidden-header-keymap + mouse-face highlight)) + (unwind-protect + (cond ((or (and (not arg) + (text-property-any begin end 'invisible 'vanish)) + (and (numberp arg) (>= arg 0)) + (and (eq arg 'long) (> (line-beginning-position 5) end))) + (remove-text-properties begin end '(invisible nil)) + (search-forward ":" (line-end-position) t) + (mh-letter-skip-leading-whitespace-in-header-field)) + ;; XXX Redesign to make usable by user. Perhaps use a positive + ;; numeric prefix to make that many lines visible. + ((eq arg 'long) + (end-of-line 4) + (mh-letter-truncate-header-field end) + (beginning-of-line)) + (t (end-of-line) + (mh-letter-truncate-header-field end) + (beginning-of-line))) + (set-buffer-modified-p modified-flag))))) + +(defun mh-open-line () + "Insert a newline and leave point before it. + +This command is similar to the command \\[open-line] in that it +inserts a newline after point. It differs in that it also inserts +the right number of quoting characters and spaces so that the +next line begins in the same column as it was. This is useful +when breaking up paragraphs in replies." + (interactive) + (let ((column (current-column)) + (prefix (mh-current-fill-prefix))) + (if (> (length prefix) column) + (message "Sorry, point seems to be within the line prefix") + (newline 2) + (insert prefix) + (while (> column (current-column)) + (insert " ")) + (forward-line -1)))) + +(defun mh-to-fcc (&optional folder) + "Move to \"Fcc:\" header field. + +This command will prompt you for the FOLDER name in which to file +a copy of the draft." + (interactive (list (mh-prompt-for-folder + "Fcc" + (or (and mh-default-folder-for-message-function + (save-excursion + (goto-char (point-min)) + (funcall + mh-default-folder-for-message-function))) + "") + t))) + (let ((last-input-char ?\C-f)) + (expand-abbrev) + (save-excursion + (mh-to-field) + (insert (if (mh-folder-name-p folder) + (substring folder 1) + folder))))) + +(defvar mh-to-field-choices '(("a" . "Mail-Reply-To:") + ("b" . "Bcc:") + ("c" . "Cc:") + ("d" . "Dcc:") + ("f" . "Fcc:") + ("l" . "Mail-Followup-To:") + ("m" . "From:") + ("r" . "Reply-To:") + ("s" . "Subject:") + ("t" . "To:")) + "Alist of (final-character . field-name) choices for `mh-to-field'.") + +(defun mh-to-field () + "Move to specified header field. + +The field is indicated by the previous keystroke (the last +keystroke of the command) according to the list in the variable +`mh-to-field-choices'. +Create the field if it does not exist. +Set the mark to point before moving." + (interactive) + (expand-abbrev) + (let ((target (cdr (or (assoc (char-to-string (logior last-input-char ?`)) + mh-to-field-choices) + ;; also look for a char for version 4 compat + (assoc (logior last-input-char ?`) + mh-to-field-choices)))) + (case-fold-search t)) + (push-mark) + (cond ((mh-position-on-field target) + (let ((eol (point))) + (skip-chars-backward " \t") + (delete-region (point) eol)) + (if (and (not (eq (logior last-input-char ?`) ?s)) + (save-excursion + (backward-char 1) + (not (looking-at "[:,]")))) + (insert ", ") + (insert " "))) + (t + (if (mh-position-on-field "To:") + (forward-line 1)) + (insert (format "%s \n" target)) + (backward-char 1))))) + +;;;###mh-autoload +(defun mh-yank-cur-msg () + "Insert the current message into the draft buffer. + +It is often useful to insert a snippet of text from a letter that +someone mailed to provide some context for your reply. This +command does this by adding an attribution, yanking a portion of +text from the message to which you're replying, and inserting +`mh-ins-buf-prefix' (`> ') before each line. + +The attribution consists of the sender's name and email address +followed by the content of the option +`mh-extract-from-attribution-verb'. + +You can also turn on the option +`mh-delete-yanked-msg-window-flag' to delete the window +containing the original message after yanking it to make more +room on your screen for your reply. + +You can control how the message to which you are replying is +yanked into your reply using `mh-yank-behavior'. + +If this isn't enough, you can gain full control over the +appearance of the included text by setting `mail-citation-hook' +to a function that modifies it. For example, if you set this hook +to `trivial-cite' (which is NOT part of Emacs), set +`mh-yank-behavior' to \"Body and Header\" (see URL +`http://shasta.cs.uiuc.edu/~lrclause/tc.html'). + +Note that if `mail-citation-hook' is set, `mh-ins-buf-prefix' is +not inserted. If the option `mh-yank-behavior' is set to one of +the supercite flavors, the hook `mail-citation-hook' is ignored +and `mh-ins-buf-prefix' is not inserted." + (interactive) + (if (and mh-sent-from-folder + (save-excursion (set-buffer mh-sent-from-folder) mh-show-buffer) + (save-excursion (set-buffer mh-sent-from-folder) + (get-buffer mh-show-buffer)) + mh-sent-from-msg) + (let ((to-point (point)) + (to-buffer (current-buffer))) + (set-buffer mh-sent-from-folder) + (if mh-delete-yanked-msg-window-flag + (delete-windows-on mh-show-buffer)) + (set-buffer mh-show-buffer) ; Find displayed message + (let* ((from-attr (mh-extract-from-attribution)) + (yank-region (mh-mark-active-p nil)) + (mh-ins-str + (cond ((and yank-region + (or (eq 'supercite mh-yank-behavior) + (eq 'autosupercite mh-yank-behavior) + (eq t mh-yank-behavior))) + ;; supercite needs the full header + (concat + (buffer-substring (point-min) (mh-mail-header-end)) + "\n" + (buffer-substring (region-beginning) (region-end)))) + (yank-region + (buffer-substring (region-beginning) (region-end))) + ((or (eq 'body mh-yank-behavior) + (eq 'attribution mh-yank-behavior) + (eq 'autoattrib mh-yank-behavior)) + (buffer-substring + (save-excursion + (goto-char (point-min)) + (mh-goto-header-end 1) + (point)) + (point-max))) + ((or (eq 'supercite mh-yank-behavior) + (eq 'autosupercite mh-yank-behavior) + (eq t mh-yank-behavior)) + (buffer-substring (point-min) (point-max))) + (t + (buffer-substring (point) (point-max)))))) + (set-buffer to-buffer) + (save-restriction + (narrow-to-region to-point to-point) + (insert (mh-filter-out-non-text mh-ins-str)) + (goto-char (point-max)) ;Needed for sc-cite-original + (push-mark) ;Needed for sc-cite-original + (goto-char (point-min)) ;Needed for sc-cite-original + (mh-insert-prefix-string mh-ins-buf-prefix) + (when (or (eq 'attribution mh-yank-behavior) + (eq 'autoattrib mh-yank-behavior)) + (insert from-attr) + (mh-identity-insert-attribution-verb nil) + (insert "\n\n")) + ;; If the user has selected a region, he has already "edited" the + ;; text, so leave the cursor at the end of the yanked text. In + ;; either case, leave a mark at the opposite end of the included + ;; text to make it easy to jump or delete to the other end of the + ;; text. + (push-mark) + (goto-char (point-max)) + (if (null yank-region) + (mh-exchange-point-and-mark-preserving-active-mark))))) + (error "There is no current message"))) + + + +;;; Support Routines + +(defun mh-auto-fill-for-letter () + "Perform auto-fill for message. +Header is treated specially by inserting a tab before continuation +lines." + (if (mh-in-header-p) + (let ((fill-prefix "\t")) + (do-auto-fill)) + (do-auto-fill))) + +(defun mh-filter-out-non-text (string) + "Return STRING but without adornments such as MIME buttons and smileys." + (with-temp-buffer + ;; Insert the string to filter + (insert string) + (goto-char (point-min)) + + ;; Remove the MIME buttons + (let ((can-move-forward t) + (in-button nil)) + (while can-move-forward + (cond ((and (not (get-text-property (point) 'mh-data)) + in-button) + (delete-region (1- (point)) (point)) + (setq in-button nil)) + ((get-text-property (point) 'mh-data) + (delete-region (point) + (save-excursion (forward-line) (point))) + (setq in-button t)) + (t (setq can-move-forward (= (forward-line) 0)))))) + + ;; Return the contents without properties... This gets rid of emphasis + ;; and smileys + (buffer-substring-no-properties (point-min) (point-max)))) + +(defun mh-current-fill-prefix () + "Return the `fill-prefix' on the current line as a string." + (save-excursion + (beginning-of-line) + ;; This assumes that the major-mode sets up adaptive-fill-regexp + ;; correctly such as mh-letter-mode or sendmail.el's mail-mode. But + ;; perhaps I should use the variable and simply inserts its value here, + ;; and set it locally in a let scope. --psg + (if (re-search-forward adaptive-fill-regexp nil t) + (match-string 0) + ""))) + +;;;###mh-autoload +(defun mh-letter-next-header-field () + "Cycle to the next header field. +If we are at the last header field go to the start of the message +body." + (let ((header-end (mh-mail-header-end))) + (cond ((>= (point) header-end) (goto-char (point-min))) + ((< (point) (progn + (beginning-of-line) + (re-search-forward mh-letter-header-field-regexp + (line-end-position) t) + (point))) + (beginning-of-line)) + (t (end-of-line))) + (cond ((re-search-forward mh-letter-header-field-regexp header-end t) + (if (mh-letter-skipped-header-field-p (match-string 1)) + (mh-letter-next-header-field) + (mh-letter-skip-leading-whitespace-in-header-field))) + (t (goto-char header-end) + (forward-line))))) + +;;;###mh-autoload +(defun mh-letter-skipped-header-field-p (field) + "Check if FIELD is to be skipped." + (let ((field (downcase field))) + (loop for x in mh-compose-skipped-header-fields + when (equal (downcase x) field) return t + finally return nil))) + +(defun mh-letter-skip-leading-whitespace-in-header-field () + "Skip leading whitespace in a header field. +If the header field doesn't have at least one space after the +colon then a space character is added." + (let ((need-space t)) + (while (memq (char-after) '(?\t ?\ )) + (forward-char) + (setq need-space nil)) + (when need-space (insert " ")))) + +;;;###mh-autoload +(defun mh-position-on-field (field &optional ignored) + "Move to the end of the FIELD in the header. +Move to end of entire header if FIELD not found. +Returns non-nil iff FIELD was found. +The optional second arg is for pre-version 4 compatibility and is +IGNORED." + (cond ((mh-goto-header-field field) + (mh-header-field-end) + t) + ((mh-goto-header-end 0) + nil))) + +(defun mh-letter-header-field-at-point () + "Return the header field name at point. +A symbol is returned whose name is the string obtained by +downcasing the field name." + (save-excursion + (end-of-line) + (and (re-search-backward mh-letter-header-field-regexp nil t) + (intern (downcase (match-string 1)))))) + +(defun mh-folder-expand-at-point () + "Do folder name completion in Fcc header field." + (let* ((end (point)) + (beg (mh-beginning-of-word)) + (folder (buffer-substring beg end)) + (leading-plus (and (> (length folder) 0) (equal (aref folder 0) ?+))) + (last-slash (mh-search-from-end ?/ folder)) + (prefix (and last-slash (substring folder 0 last-slash))) + (choices (mapcar #'(lambda (x) + (list (cond (prefix (format "%s/%s" prefix x)) + (leading-plus (format "+%s" x)) + (t x)))) + (mh-folder-completion-function folder nil t)))) + (mh-complete-word folder choices beg end))) + +;;;###mh-autoload +(defun mh-complete-word (word choices begin end) + "Complete WORD at from CHOICES. +Any match found replaces the text from BEGIN to END." + (let ((completion (try-completion word choices)) + (completions-buffer "*Completions*")) + (cond ((eq completion t) + (ignore-errors + (kill-buffer completions-buffer)) + (message "Completed: %s" word)) + ((null completion) + (ignore-errors + (kill-buffer completions-buffer)) + (message "No completion for %s" word)) + ((stringp completion) + (if (equal word completion) + (with-output-to-temp-buffer completions-buffer + (mh-display-completion-list (all-completions word choices) + choices)) + (ignore-errors + (kill-buffer completions-buffer)) + (delete-region begin end) + (insert completion)))))) + +(defun mh-file-is-vcard-p (file) + "Return t if FILE is a .vcf vcard." + (let ((case-fold-search t)) + (and (stringp file) + (file-exists-p file) + (or (and (not (mh-have-file-command)) + (not (null (string-match "\.vcf$" file)))) + (string-equal "text/x-vcard" (mh-file-mime-type file)))))) + +(defun mh-letter-toggle-header-field-display-button (event) + "Toggle header field display at location of EVENT. +This function does the same thing as +`mh-letter-toggle-header-field-display' except that it is +callable from a mouse button." + (interactive "e") + (mh-do-at-event-location event + (mh-letter-toggle-header-field-display nil))) + +(defun mh-letter-truncate-header-field (end) + "Replace text from current line till END with an ellipsis. +If the current line is too long truncate a part of it as well." + (let ((max-len (min (window-width) 62))) + (when (> (+ (current-column) 4) max-len) + (backward-char (- (+ (current-column) 5) max-len))) + (when (> end (point)) + (add-text-properties (point) end '(invisible vanish))))) + +(defun mh-extract-from-attribution () + "Extract phrase or comment from From header field." + (save-excursion + (if (not (mh-goto-header-field "From: ")) + nil + (skip-chars-forward " ") + (cond + ((looking-at "\"\\([^\"\n]+\\)\" \\(<.+>\\)") + (format "%s %s " (match-string 1)(match-string 2))) + ((looking-at "\\([^<\n]+<.+>\\)$") + (format "%s " (match-string 1))) + ((looking-at "\\([^ ]+@[^ ]+\\) +(\\(.+\\))$") + (format "%s <%s> " (match-string 2)(match-string 1))) + ((looking-at " *\\(.+\\)$") + (format "%s " (match-string 1))))))) + +(defun mh-insert-prefix-string (mh-ins-string) + "Insert prefix string before each line in buffer. +The inserted letter is cited using `sc-cite-original' if +`mh-yank-behavior' is one of 'supercite or 'autosupercite. +Otherwise, simply insert MH-INS-STRING before each line." + (goto-char (point-min)) + (cond ((or (eq mh-yank-behavior 'supercite) + (eq mh-yank-behavior 'autosupercite)) + (sc-cite-original)) + (mail-citation-hook + (run-hooks 'mail-citation-hook)) + (mh-yank-hooks ;old hook name + (run-hooks 'mh-yank-hooks)) + (t + (or (bolp) (forward-line 1)) + (while (< (point) (point-max)) + (insert mh-ins-string) + (forward-line 1)) + (goto-char (point-min))))) ;leave point like sc-cite-original + +(provide 'mh-letter) + +;; Local Variables: +;; indent-tabs-mode: nil +;; sentence-end-double-space: nil +;; End: + +;;; mh-letter.el ends here