- (goto-char beg)
- (beginning-of-line)
- (while (< (point) end)
- (let ((beg-sub (point-marker))
- (indent (make-string depth ? ))
- (citation ">"))
- (move-to-column depth)
- (if (looking-at citation)
- (progn
- (while (looking-at citation)
- (forward-line)
- (move-to-column depth))
- (let ((overlay (make-overlay beg-sub (point)))
- (invis-spec (make-symbol "notmuch-citation-region")))
- (add-to-invisibility-spec invis-spec)
- (overlay-put overlay 'invisible invis-spec)
- (let ((p (point-marker))
- (cite-button-text
- (concat "[" (number-to-string (count-lines beg-sub (point)))
- "-line citation.]")))
- (goto-char (- beg-sub 1))
- (insert (concat "\n" indent))
- (insert-button cite-button-text
- 'invisibility-spec invis-spec
- :type 'notmuch-button-citation-toggle-type)
- (insert "\n")
- (goto-char (+ (length cite-button-text) p))
- ))))
- (move-to-column depth)
- (if (looking-at notmuch-show-signature-regexp)
- (let ((sig-lines (- (count-lines beg-sub end) 1)))
- (if (<= sig-lines notmuch-show-signature-lines-max)
- (progn
- (let ((invis-spec (make-symbol "notmuch-signature-region")))
- (add-to-invisibility-spec invis-spec)
- (overlay-put (make-overlay beg-sub end)
- 'invisible invis-spec)
-
- (goto-char (- beg-sub 1))
- (insert (concat "\n" indent))
- (let ((sig-button-text (concat "[" (number-to-string sig-lines)
- "-line signature. Click/Enter to show.]")))
- (insert-button sig-button-text 'invisibility-spec invis-spec
- :type 'notmuch-button-signature-toggle-type)
- )
- (insert "\n")
- (goto-char end))))))
- (forward-line))))
+ "Markup citations, and up to one signature in the given region"
+ ;; it would be nice if the untabify was not required, but
+ ;; that would require notmuch to indent with spaces.
+ (untabify beg end)
+ (let ((citation-regexp (notmuch-show-citation-regexp depth))
+ (signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth)
+ notmuch-show-signature-regexp))
+ (indent (concat "\n" (make-string depth ? ))))
+ (goto-char beg)
+ (beginning-of-line)
+ (while (and (< (point) end)
+ (re-search-forward citation-regexp end t))
+ (let* ((cite-start (match-beginning 0))
+ (cite-end (match-end 0))
+ (cite-lines (count-lines cite-start cite-end)))
+ (when (> cite-lines (1+ notmuch-show-citation-lines-prefix))
+ (goto-char cite-start)
+ (forward-line notmuch-show-citation-lines-prefix)
+ (notmuch-show-region-to-button
+ (point) cite-end
+ "citation"
+ indent
+ (format notmuch-show-citation-button-format
+ (- cite-lines notmuch-show-citation-lines-prefix))
+ ))))
+ (if (and (< (point) end)
+ (re-search-forward signature-regexp end t))
+ (let* ((sig-start (match-beginning 0))
+ (sig-end (match-end 0))
+ (sig-lines (1- (count-lines sig-start end))))
+ (if (<= sig-lines notmuch-show-signature-lines-max)
+ (notmuch-show-region-to-button
+ sig-start
+ end
+ "signature"
+ indent
+ (format notmuch-show-signature-button-format sig-lines)
+ ))))))