Re: Trimming email replies in gnus/message-mode

Martin Kjær Jørgensen via Users list for the GNU Emacs text editor <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
On 04/23/26 22:59 PM, [email protected] wrote:
> Martin Kjær Jørgensen <[email protected]> writes:
>
>> Hey,
>>
>> To those of you who uses gnus+message-mode in your daily lives; how do you
>> trim quoted text when replying (posting) emails? 
>>
>> Do you manually remove excess reply level texts, or do you have some function
>> or enabled variables that takes care of it automatically? Especially when
>> dealing with "large" replies.
>
> If I understand your question/problem correctly, then you
> want to be able to remove successive levels of replies, from
> the outermost through any number of levels down possibly to
> the innermost.
>
>    > level 1
>    > 
>    > > level 2
>    > > 
>    > > > level 3
>    > > >
>    > > > > level 4
>
> So, you could remove level 1 and then have:
>
>    > level 2
>    > 
>    > > level 3
>    > >
>    > > > level 4
>
> You could remove level 2 (now at level 1) and then have:
>
>    > level 3
>    >
>    > > level 4
>
> And so on, depending on what you wanted in your reply.
>
> If this describes the problem that you want correctly, then
> here is command definition that you could try:
>
> (require 'message)
>
> (defun delete-top-level ()
>   "Delete the top-level reply lines from a buffer in Message mode."
>   (interactive)
>   (if (eq major-mode 'message-mode)
>       ;; Restrict all editing to lines from the beginning of the message
>       ;; body down to either the line before the signature or the end of
>       ;; the buffer, if there is no signature.
>       (let ((begin (progn
>                      (message-goto-body)
>                      (point)))
>             (end (progn
>                    (when (message-goto-signature)
>                      (forward-line -2))
>                    (point))))
>         ;; Delete all lines that have either:
>         ;;   - only a ‘>’ on the line
>         ;;   - a line that starts with ‘>’, followed by at least one
>         ;;     non-‘>’ character, followed by any character
>         (delete-matching-lines "^>$\\|^>[^>].*$" begin end)
>
>         ;; In the lines that remain, replace any lines that:
>         ;;   - start with a ‘>’, followed by any characters
>         ;; with a line that:
>         ;;   - consists of all of the characters after the
>         ;;     ‘>’ character
>         (replace-regexp "^>\\(.*\\)" "\\1" nil begin end))
>     ;; Otherwise...
>     (user-error "This command only works in message buffers")))
>
> You would run this command in a Message buffer after you
> yanked the original (for example, using
> ‘message-yank-original’).
>
> Note that ‘replace-regexp’ is supposed to be used
> interactively only.  In Elisp code, the functions
> ‘re-search-forward’ and ‘replace-match’ are supposed to be
> used instead.  I am leaving replacement of ‘replace-regexp’
> as an exercise.
>
> -- 
> The lyf so short, the craft so long to lerne.
> - Geoffrey Chaucer, The Parliament of Birds.

Thank you :-) . That is very close to what I was thinking about. I'll try it
out, and maybe adapt it a bit.

-- 
/Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.