📄 rmail.el
字号:
(forward-char -1) (search-forward "\n*** EOOH ***\n") (forward-line -1) (let ((temp (point))) (and (search-forward "\n\n" nil t) (delete-region temp (point)))) (goto-char (point-min)) (search-forward "\n*** EOOH ***\n") (narrow-to-region (point) (point-max))) (rmail-reformat-message (point-min) (point-max)))));;;; *** Rmail Attributes and Keywords ***;; Make a string describing current message's attributes and keywords;; and set it up as the name of a minor mode;; so it will appear in the mode line.(defun rmail-display-labels () (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker))) (save-excursion (unwind-protect (progn (widen) (goto-char (rmail-msgbeg rmail-current-message)) (forward-line 1) (if (looking-at "[01],") (progn (narrow-to-region (point) (progn (end-of-line) (point))) ;; Truly valid BABYL format requires a space before each ;; attribute or keyword name. Put them in if missing. (let (buffer-read-only) (goto-char (point-min)) (while (search-forward "," nil t) (or (looking-at "[ ,]") (eobp) (insert " ")))) (goto-char (point-max)) (if (search-backward ",," nil 'move) (progn (if (> (point) (1+ (point-min))) (setq blurb (buffer-substring (+ 1 (point-min)) (point)))) (if (> (- (point-max) (point)) 2) (setq blurb (concat blurb ";" (buffer-substring (+ (point) 3) (1- (point-max))))))))))) (narrow-to-region beg end) (set-marker beg nil) (set-marker end nil))) (while (string-match " +," blurb) (setq blurb (concat (substring blurb 0 (match-beginning 0)) "," (substring blurb (match-end 0))))) (while (string-match ", +" blurb) (setq blurb (concat (substring blurb 0 (match-beginning 0)) "," (substring blurb (match-end 0))))) (setq mode-line-process (concat " " rmail-current-message "/" rmail-total-messages blurb))));; Turn an attribute of the current message on or off according to STATE.;; ATTR is the name of the attribute, as a string.(defun rmail-set-attribute (attr state) (let ((omax (- (buffer-size) (point-max))) (omin (- (buffer-size) (point-min))) (buffer-read-only nil)) (unwind-protect (save-excursion (widen) (goto-char (+ 3 (rmail-msgbeg rmail-current-message))) (let ((curstate (search-backward (concat ", " attr ",") (prog1 (point) (end-of-line)) t))) (or (eq curstate (not (not state))) (if curstate (delete-region (point) (1- (match-end 0))) (beginning-of-line) (forward-char 2) (insert " " attr ",")))) (if (string= attr "deleted") (rmail-set-message-deleted-p rmail-current-message state))) (narrow-to-region (max 1 (- (buffer-size) omin)) (- (buffer-size) omax)) (rmail-display-labels))));; Return t if the attributes/keywords line of msg number MSG;; contains a match for the regexp LABELS.(defun rmail-message-labels-p (msg labels) (goto-char (rmail-msgbeg msg)) (forward-char 3) (re-search-backward labels (prog1 (point) (end-of-line)) t));;;; *** Rmail Message Selection And Support ***(defun rmail-msgend (n) (marker-position (aref rmail-message-vector (1+ n))))(defun rmail-msgbeg (n) (marker-position (aref rmail-message-vector n)))(defun rmail-widen-to-current-msgbeg (function) "Call FUNCTION with point at start of internal data of current message.Assumes that bounds were previously narrowed to display the message in Rmail.The bounds are widened enough to move point where desired,then narrowed again afterward.Assumes that the visible text of the message is not changed by FUNCTION." (save-excursion (let ((obeg (- (point-max) (point-min))) (unwind-protect (progn (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max)) (goto-char (point-min)) (funcall function)) (narrow-to-region (- (point-max) obeg) (point-max)))))))(defun rmail-forget-messages () (unwind-protect (if (vectorp rmail-message-vector) (let* ((i 0) (v rmail-message-vector) (n (length v))) (while (< i n) (move-marker (aref v i) nil) (setq i (1+ i))))) (setq rmail-message-vector nil) (setq rmail-deleted-vector nil)))(defun rmail-maybe-set-message-counters () (if (not (and rmail-deleted-vector rmail-message-vector rmail-current-message rmail-total-messages)) (rmail-set-message-counters)))(defun rmail-count-new-messages (&optional nomsg) (let* ((case-fold-search nil) (total-messages 0) (messages-head nil) (deleted-head nil)) (or nomsg (message "Counting new messages...")) (goto-char (point-max)) ;; Put at the end of messages-head ;; the entry for message N+1, which marks ;; the end of message N. (N = number of messages). (search-backward "\^_") (setq messages-head (list (point-marker))) (rmail-set-message-counters-counter (point-min)) (setq rmail-current-message (1+ rmail-total-messages)) (setq rmail-total-messages (+ rmail-total-messages total-messages)) (setq rmail-message-vector (vconcat rmail-message-vector (cdr messages-head))) (aset rmail-message-vector rmail-current-message (car messages-head)) (setq rmail-deleted-vector (concat rmail-deleted-vector deleted-head)) (setq rmail-summary-vector (vconcat rmail-summary-vector (make-vector total-messages nil))) (goto-char (point-min)) (or nomsg (message "Counting new messages...done (%d)" total-messages))))(defun rmail-set-message-counters () (rmail-forget-messages) (save-excursion (save-restriction (widen) (let* ((point-save (point)) (total-messages 0) (messages-after-point) (case-fold-search nil) (messages-head nil) (deleted-head nil)) (message "Counting messages...") (goto-char (point-max)) ;; Put at the end of messages-head ;; the entry for message N+1, which marks ;; the end of message N. (N = number of messages). (search-backward "\^_") (setq messages-head (list (point-marker))) (rmail-set-message-counters-counter (min (point) point-save)) (setq messages-after-point total-messages) (rmail-set-message-counters-counter) (setq rmail-total-messages total-messages) (setq rmail-current-message (min total-messages (max 1 (- total-messages messages-after-point)))) (setq rmail-message-vector (apply 'vector (cons (point-min-marker) messages-head)) rmail-deleted-vector (concat "D" deleted-head) rmail-summary-vector (make-vector rmail-total-messages nil)) (message "Counting messages...done"))))) (defun rmail-set-message-counters-counter (&optional stop) (while (search-backward "\^_\^L\n" stop t) (setq messages-head (cons (point-marker) messages-head)) (save-excursion (setq deleted-head (cons (if (search-backward ", deleted," (prog1 (point) (forward-line 2)) t) ?D ?\ ) deleted-head))) (if (zerop (% (setq total-messages (1+ total-messages)) 20)) (message "Counting messages...%d" total-messages))))(defun rmail-beginning-of-message () "Show current message starting from the beginning." (interactive) (rmail-show-message rmail-current-message))(defun rmail-show-message (&optional n) "Show message number N (prefix argument), counting from start of file." (interactive "p") (rmail-maybe-set-message-counters) (widen) (if (zerop rmail-total-messages) (progn (narrow-to-region (point-min) (1- (point-max))) (goto-char (point-min)) (setq mode-line-process nil)) (let (blurb) (if (not n) (setq n rmail-current-message) (cond ((<= n 0) (setq n 1 rmail-current-message 1 blurb "No previous message")) ((> n rmail-total-messages) (setq n rmail-total-messages rmail-current-message rmail-total-messages blurb "No following message")) (t (setq rmail-current-message n)))) (let ((beg (rmail-msgbeg n)) (end (rmail-msgend n))) (goto-char beg) (forward-line 1) (if (= (following-char) ?0) (progn (rmail-reformat-message beg end) (rmail-set-attribute "unseen" nil)) (search-forward "\n*** EOOH ***\n" end t) (narrow-to-region (point) end)) (goto-char (point-min)) (rmail-display-labels) (run-hooks 'rmail-show-message-hook) (if blurb (message blurb))))))(defun rmail-next-message (n) "Show following message whether deleted or not.With prefix argument N, moves forward N messages,or backward if N is negative." (interactive "p") (rmail-maybe-set-message-counters) (rmail-show-message (+ rmail-current-message n)))(defun rmail-previous-message (n) "Show previous message whether deleted or not.With prefix argument N, moves backward N messages,or forward if N is negative." (interactive "p") (rmail-next-message (- n))) (defun rmail-next-undeleted-message (n) "Show following non-deleted message.With prefix argument N, moves forward N non-deleted messages,or backward if N is negative." (interactive "p") (rmail-maybe-set-message-counters) (let ((lastwin rmail-current-message) (current rmail-current-message)) (while (and (> n 0) (< current rmail-total-messages)) (setq current (1+ current)) (if (not (rmail-message-deleted-p current)) (setq lastwin current n (1- n)))) (while (and (< n 0) (> current 1)) (setq current (1- current)) (if (not (rmail-message-deleted-p current)) (setq lastwin current n (1+ n)))) (if (/= lastwin rmail-current-message) (rmail-show-message lastwin)) (if (< n 0) (message "No previous nondeleted message")) (if (> n 0) (message "No following nondeleted message"))))(defun rmail-previous-undeleted-message (n) "Show previous non-deleted message.With prefix argument N, moves backward N non-deleted messages,or forward if N is negative." (interactive "p") (rmail-next-undeleted-message (- n)))(defun rmail-last-message () "Show last message in file." (interactive) (rmail-maybe-set-message-counters) (rmail-show-message rmail-total-messages))(defun rmail-what-message () (let ((where (point)) (low 1) (high rmail-total-messages) (mid (/ rmail-total-messages 2))) (while (> (- high low) 1) (if (>= where (rmail-msgbeg mid)) (setq low mid) (setq high mid)) (setq mid (+ low (/ (- high low) 2)))) (if (>= where (rmail-msgbeg high)) high low)))(defvar rmail-search-last-regexp nil)(defun rmail-search (regexp &optional reversep) "Show message containing next match for REGEXP.Search in reverse (earlier messages) with non-nil 2nd arg REVERSEP.Interactively, empty argument means use same regexp used last time,and reverse search is specified by a negative numeric arg." (interactive (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0)) (prompt (concat (if reversep "Reverse " "") "Rmail search (regexp): ")) regexp) (if rmail-search-last-regexp (setq prompt (concat prompt "(default " rmail-search-last-regexp ") "))) (setq regexp (read-string prompt)) (cond ((not (equal regexp "")) (setq rmail-search-last-regexp regexp)) ((not rmail-search-last-regexp) (error "No previous Rmail search string"))) (list rmail-search-last-regexp reversep))) (message "%sRmail search for %s..." (if reversep "Reverse " "") regexp) (rmail-maybe-set-message-counters) (let ((omin (point-min)) (omax (point-max)) (opoint (point)) win (msg rmail-current-message)) (unwind-protect (progn (widen) ;; Check messages one by one, advancing message number up or down ;; but searching forward through each message. (if reversep (while (and (null win) (> msg 1)) (goto-char (rmail-msgbeg (setq msg (1- msg)))) (setq win (re-search-forward
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -