| 1 |
;;; mew-message.el --- Message mode for Mew |
| 2 |
|
| 3 |
;; Author: Kazu Yamamoto <[email protected]> |
| 4 |
;; Created: Oct 2, 1996 |
| 5 |
|
| 6 |
;;; Code: |
| 7 |
|
| 8 |
(require 'mew) |
| 9 |
|
| 10 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 11 |
;;; |
| 12 |
;;; Message info |
| 13 |
;;; |
| 14 |
|
| 15 |
(defvar mew-minfo-list '("summary" "eom" "veil-to" "veil-cc" "reob")) |
| 16 |
|
| 17 |
(mew-blinfo-defun 'mew-minfo mew-minfo-list) |
| 18 |
|
| 19 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 20 |
;;; |
| 21 |
;;; Message mode |
| 22 |
;;; |
| 23 |
|
| 24 |
(defun mew-message-mode () |
| 25 |
"A major mode for display a message. |
| 26 |
|
| 27 |
\\{mew-message-mode-map}" |
| 28 |
(interactive) |
| 29 |
(setq major-mode 'mew-message-mode) |
| 30 |
(setq mode-name mew-mode-name-message) |
| 31 |
(setq mode-line-buffer-identification (mew-mode-line-id)) |
| 32 |
(use-local-map mew-message-mode-map) |
| 33 |
(setq buffer-read-only t) |
| 34 |
(make-local-variable 'page-delimiter) |
| 35 |
(setq page-delimiter mew-page-delimiter) |
| 36 |
(mew-message-setup-decoration) |
| 37 |
(mew-message-toolbar-update) |
| 38 |
(mew-run-mode-hooks 'mew-message-mode-hook)) |
| 39 |
|
| 40 |
(defun mew-message-mode-line (fld message) |
| 41 |
(let* ((msg (or message |
| 42 |
(mew-current-get-msg (mew-frame-id)))) |
| 43 |
(status (mew-message-line-status)) |
| 44 |
(flag (nth status '("N" "W" "L")))) |
| 45 |
(when msg |
| 46 |
(setq mode-line-process (format " %s %s/%s" flag fld msg))))) |
| 47 |
|
| 48 |
(defun mew-message-next-page (&optional lines) |
| 49 |
"Scroll up this message. Return 'nil' if more pages. Otherwise, return 't'." |
| 50 |
(interactive) |
| 51 |
(if (save-excursion |
| 52 |
(goto-char (window-end)) |
| 53 |
(and (pos-visible-in-window-p) (eobp))) |
| 54 |
;; Nothing in this page. |
| 55 |
(if (or (null mew-break-pages) |
| 56 |
(save-excursion |
| 57 |
(goto-char (window-end)) |
| 58 |
(save-restriction |
| 59 |
(widen) (forward-line) (eobp)))) ;; Real end of buffer? |
| 60 |
(if mew-summary-show-pause |
| 61 |
(prog1 |
| 62 |
(mew-minfo-get-reob) |
| 63 |
(unless (mew-minfo-get-reob) |
| 64 |
(message "End of buffer") |
| 65 |
(mew-minfo-set-reob t))) |
| 66 |
t) |
| 67 |
;; Go to the next page. |
| 68 |
(mew-message-narrow-to-page 1) |
| 69 |
nil) |
| 70 |
;; More in this page. |
| 71 |
(condition-case nil |
| 72 |
(scroll-up lines) |
| 73 |
(end-of-buffer |
| 74 |
(goto-char (point-max)) |
| 75 |
(message "End of buffer"))) |
| 76 |
nil)) |
| 77 |
|
| 78 |
(defun mew-message-prev-page (&optional lines) |
| 79 |
"Back-scroll this message. Return 'nil' if more pages. |
| 80 |
Otherwise, return 't'." |
| 81 |
(interactive) |
| 82 |
(move-to-window-line 0) |
| 83 |
(if (save-excursion |
| 84 |
(beginning-of-line) |
| 85 |
(and (pos-visible-in-window-p) (bobp))) |
| 86 |
;; Nothing in this page. |
| 87 |
(if (or (null mew-break-pages) |
| 88 |
(save-restriction |
| 89 |
(widen) (bobp))) ;; Real beginning of buffer? |
| 90 |
t |
| 91 |
;; Go to the previous page. |
| 92 |
(mew-message-narrow-to-page -1) |
| 93 |
nil) |
| 94 |
;; More in this page. |
| 95 |
(condition-case nil |
| 96 |
(scroll-down lines) |
| 97 |
(beginning-of-buffer |
| 98 |
(goto-char (point-min)) |
| 99 |
(message "Beginning of buffer"))) |
| 100 |
nil)) |
| 101 |
|
| 102 |
(defun mew-message-narrow-to-page (&optional arg) |
| 103 |
(setq arg (if arg (prefix-numeric-value arg) 0)) |
| 104 |
(save-excursion |
| 105 |
(condition-case nil |
| 106 |
(forward-page -1) ;; Beginning of the current page. |
| 107 |
(beginning-of-buffer ())) |
| 108 |
(widen) |
| 109 |
(cond |
| 110 |
((> arg 0) (forward-page arg)) |
| 111 |
((< arg 0) (forward-page (1- arg)))) |
| 112 |
(forward-page) |
| 113 |
(let* ((end (point))) |
| 114 |
(forward-page -1) |
| 115 |
(if (and (eolp) (not (bobp))) |
| 116 |
(forward-line)) |
| 117 |
(narrow-to-region (point) end)))) |
| 118 |
|
| 119 |
(defun mew-message-goto-summary () |
| 120 |
"Get back to Summary mode." |
| 121 |
(interactive) |
| 122 |
(let* ((fld (mew-minfo-get-summary)) |
| 123 |
(fid (mew-frame-id)) |
| 124 |
(msg (mew-current-get-msg fid)) |
| 125 |
(part (mew-current-get-part fid))) |
| 126 |
(if (not (get-buffer fld)) |
| 127 |
(message "No Summary mode for %s" fld) |
| 128 |
(if (get-buffer-window fld) |
| 129 |
(select-window (get-buffer-window fld)) |
| 130 |
(mew-summary-switch-to-folder fld)) |
| 131 |
(cond |
| 132 |
((and msg part (mew-decode-syntax-p)) |
| 133 |
(setq part (concat "^.. +" |
| 134 |
(regexp-quote (mapconcat 'number-to-string part ".")) |
| 135 |
" ")) |
| 136 |
(goto-char (mew-decode-syntax-begin)) |
| 137 |
(re-search-forward part (mew-decode-syntax-end) t) |
| 138 |
(beginning-of-line) |
| 139 |
(mew-summary-display)) |
| 140 |
(msg |
| 141 |
(mew-summary-move-and-display msg)))))) |
| 142 |
|
| 143 |
(defun mew-message-reply () |
| 144 |
"Answer to this message. A new draft is prepared in Draft mode. |
| 145 |
Mew automatically decides To: and Cc:." |
| 146 |
(interactive) |
| 147 |
(mew-message-goto-summary) |
| 148 |
(call-interactively 'mew-summary-reply)) |
| 149 |
|
| 150 |
(defun mew-message-reply-with-citation () |
| 151 |
"Answer to this message. A new draft is prepared in Draft mode. |
| 152 |
Mew automatically decides To: and Cc: and cites the body." |
| 153 |
(interactive) |
| 154 |
(mew-message-goto-summary) |
| 155 |
(call-interactively 'mew-summary-reply-with-citation)) |
| 156 |
|
| 157 |
(defun mew-message-forward () |
| 158 |
"Forward this message to a third person. A new draft is prepared in |
| 159 |
Draft mode and this message is automatically attached." |
| 160 |
(interactive) |
| 161 |
(mew-message-goto-summary) |
| 162 |
(call-interactively 'mew-summary-forward)) |
| 163 |
|
| 164 |
(defun mew-message-resend () |
| 165 |
"\\<mew-message-mode-map> |
| 166 |
Resend this message with Resent-To:. It is strongly |
| 167 |
discouraged to use this command since beginners are always |
| 168 |
confused. Please use '\\[mew-message-forward]' instead." |
| 169 |
(interactive) |
| 170 |
(mew-message-goto-summary) |
| 171 |
(call-interactively 'mew-summary-resend)) |
| 172 |
|
| 173 |
(defun mew-message-next-msg (&optional arg) |
| 174 |
"Display a message or a part below." |
| 175 |
(interactive "p") |
| 176 |
(let* ((swin (previous-window)) |
| 177 |
(mbuf (current-buffer))) |
| 178 |
(select-window swin) ;; for the next forward-line |
| 179 |
(when (mew-summary-or-virtual-p) |
| 180 |
(forward-line arg) ;; minus arg results in prev |
| 181 |
(mew-summary-display)) |
| 182 |
;; for window config |
| 183 |
(select-window (get-buffer-window mbuf)))) |
| 184 |
|
| 185 |
(defun mew-message-prev-msg (&optional arg) |
| 186 |
"Display a message or a part above." |
| 187 |
(interactive "p") |
| 188 |
(mew-message-next-msg (- arg))) |
| 189 |
|
| 190 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 191 |
;;; |
| 192 |
;;; URLs |
| 193 |
;;; |
| 194 |
|
| 195 |
(defun mew-message-goto-next-url (&optional arg) |
| 196 |
(interactive "P") |
| 197 |
(let ((next (if arg |
| 198 |
'previous-single-property-change |
| 199 |
'next-single-property-change)) |
| 200 |
pos) |
| 201 |
(setq pos (funcall next (point) 'mew-url)) |
| 202 |
(if pos |
| 203 |
(if (not (get-text-property pos 'mew-url)) |
| 204 |
(setq pos (funcall next pos 'mew-url)))) |
| 205 |
(when pos |
| 206 |
(goto-char pos)))) |
| 207 |
|
| 208 |
(defun mew-browse-url-at-mouse (event) |
| 209 |
(interactive "e") |
| 210 |
(let ((buf (current-buffer)) url) |
| 211 |
(mouse-set-point event) |
| 212 |
(setq url (or (get-text-property (point) 'mew-url) |
| 213 |
(get-text-property (point) 'w3m-href-anchor) |
| 214 |
(get-text-property (point) 'shr-url))) |
| 215 |
(if (and url (string-match mew-regex-nonascii url)) |
| 216 |
(setq url (mew-puny-encode-url url))) |
| 217 |
(if url (browse-url url)) |
| 218 |
(pop-to-buffer buf))) |
| 219 |
|
| 220 |
(defun mew-browse-url-at-point () |
| 221 |
(interactive) |
| 222 |
(let (url) |
| 223 |
(setq url (or (get-text-property (point) 'mew-url) |
| 224 |
(get-text-property (point) 'w3m-href-anchor) |
| 225 |
(get-text-property (point) 'shr-url))) |
| 226 |
(if (and url (string-match mew-regex-nonascii url)) |
| 227 |
(setq url (mew-puny-encode-url url))) |
| 228 |
(if url (browse-url url)))) |
| 229 |
|
| 230 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 231 |
;;; |
| 232 |
;;; lines |
| 233 |
;;; |
| 234 |
|
| 235 |
(defun mew-message-line-status () |
| 236 |
(cond |
| 237 |
((not (eq buffer-undo-list t)) 1) ;; wrapped |
| 238 |
(truncate-lines 2) ;; long |
| 239 |
(t 0))) ;; normal |
| 240 |
|
| 241 |
(defun mew-message-line () |
| 242 |
"Toggle normal lines, wrapped lines and long lines." |
| 243 |
(interactive) |
| 244 |
(let* ((N 3) |
| 245 |
(status (% (1+ (mew-message-line-status)) N))) |
| 246 |
(mew-elet |
| 247 |
(cond |
| 248 |
((= status 0) |
| 249 |
(setq truncate-lines nil) |
| 250 |
(message "Normal lines")) |
| 251 |
((= status 1) |
| 252 |
(setq buffer-undo-list nil) |
| 253 |
(mew-wrap-lines (if (mew-header-end) (1+ (mew-header-end)) (point-min)) (point-max)) |
| 254 |
(message "Wrapped lines")) |
| 255 |
((= status 2) |
| 256 |
(save-excursion |
| 257 |
(primitive-undo (length buffer-undo-list) buffer-undo-list)) |
| 258 |
(buffer-disable-undo) |
| 259 |
(setq truncate-lines t) |
| 260 |
(message "Long lines"))) |
| 261 |
(set-window-hscroll (selected-window) 0) |
| 262 |
(set-buffer-modified-p nil)))) |
| 263 |
|
| 264 |
(defun mew-normal-line () |
| 265 |
(setq truncate-lines nil)) |
| 266 |
|
| 267 |
(defcustom mew-wrap-lines-column fill-column |
| 268 |
"*Number of fill column to wrap line." |
| 269 |
:group 'mew-message |
| 270 |
:type 'integer) |
| 271 |
|
| 272 |
(defun mew-wrap-lines (beg end) |
| 273 |
(save-restriction |
| 274 |
(narrow-to-region beg end) |
| 275 |
(save-excursion |
| 276 |
(goto-char (point-min)) |
| 277 |
(let ((adaptive-fill-mode nil) |
| 278 |
(winwidth (- (window-width) 2)) |
| 279 |
(fill-column mew-wrap-lines-column) |
| 280 |
width start fill-prefix) |
| 281 |
(while (not (eobp)) |
| 282 |
(setq start (point)) |
| 283 |
(setq fill-prefix (mew-fill-match-adaptive-prefix)) |
| 284 |
(end-of-line) |
| 285 |
(setq width (current-column)) |
| 286 |
(forward-line) |
| 287 |
(if fill-prefix |
| 288 |
(setq fill-column (+ mew-wrap-lines-column (string-width fill-prefix))) |
| 289 |
(setq fill-column mew-wrap-lines-column)) |
| 290 |
(setq fill-column (min fill-column winwidth)) |
| 291 |
(when (> width fill-column) |
| 292 |
(fill-region-as-paragraph start (1- (point))))))))) |
| 293 |
|
| 294 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 295 |
;;; |
| 296 |
;;; Horizontal Scrolling |
| 297 |
;;; |
| 298 |
|
| 299 |
(defun mew-message-scroll-left () |
| 300 |
"Scroll the Message window to the right." |
| 301 |
(interactive) |
| 302 |
(call-interactively 'scroll-left)) |
| 303 |
|
| 304 |
(defun mew-message-scroll-right () |
| 305 |
"Scroll the Message window to the left." |
| 306 |
(interactive) |
| 307 |
(call-interactively 'scroll-right)) |
| 308 |
|
| 309 |
(provide 'mew-message) |
| 310 |
|
| 311 |
;;; Copyright Notice: |
| 312 |
|
| 313 |
;; Copyright (C) 1996-2015 Mew developing team. |
| 314 |
;; All rights reserved. |
| 315 |
|
| 316 |
;; Redistribution and use in source and binary forms, with or without |
| 317 |
;; modification, are permitted provided that the following conditions |
| 318 |
;; are met: |
| 319 |
;; |
| 320 |
;; 1. Redistributions of source code must retain the above copyright |
| 321 |
;; notice, this list of conditions and the following disclaimer. |
| 322 |
;; 2. Redistributions in binary form must reproduce the above copyright |
| 323 |
;; notice, this list of conditions and the following disclaimer in the |
| 324 |
;; documentation and/or other materials provided with the distribution. |
| 325 |
;; 3. Neither the name of the team nor the names of its contributors |
| 326 |
;; may be used to endorse or promote products derived from this software |
| 327 |
;; without specific prior written permission. |
| 328 |
;; |
| 329 |
;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 330 |
;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 331 |
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 332 |
;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 333 |
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 334 |
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 335 |
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 336 |
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 337 |
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 338 |
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 339 |
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 340 |
|
| 341 |
;;; mew-message.el ends here |