From bccd41294283db280869e8121def831c94ad6bb6 Mon Sep 17 00:00:00 2001 From: Philippe Dosch <Philippe.Dosch@loria.fr> Date: Wed, 24 Apr 2024 11:49:41 +0200 Subject: [PATCH] =?UTF-8?q?scissors=20et=20snip-lines-mail=20d=C3=A9finis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .emacs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.emacs b/.emacs index 19fc437..c0bf32f 100644 --- a/.emacs +++ b/.emacs @@ -1074,6 +1074,43 @@ ;; le code décimal) (global-set-key [181] 'mailcut) +(defvar scissors ">8 --------------------------------------------------------------- 8<" +"String to insert in \\[scissors].") +(defun scissors() + "Insert a line of SCISSORS in the buffer" + (interactive) + (insert scissors) + (forward-line 1)) +(global-set-key (kbd "M-s s") 'scissors) + +(defun snip-lines-mail () + "Delete all lines except the first three in the current buffer selection. +For the first and last remaining lines, remove all characters after the prefix composed of spaces and '>'. +For the middle line, remove all characters after the prefix and insert '[snip]' after the remaining prefix." + (interactive) + (save-excursion + (let ((begin (region-beginning)) + (end (region-end))) + (goto-char end) + (forward-line -1) + (setq end (point)) + (goto-char begin) + (forward-line 2) + (setq begin (point)) + (delete-region begin end) + (goto-char begin) + (forward-line -2) + (if (re-search-forward "^\\([ >]*\\)\\(.*\\)$" nil t) + (replace-match "" nil nil nil 2)) + (forward-line 1) + (if (re-search-forward "^\\([ >]*\\)\\(.*\\)$" nil t) + (replace-match "[snip]" nil nil nil 2)) + (forward-line 1) + (if (re-search-forward "^\\([ >]*\\)\\(.*\\)$" nil t) + (replace-match "" nil nil nil 2)) + (forward-line 1)))) +(global-set-key (kbd "M-s l") 'snip-lines-mail) + ;;; .emacs ends here (provide '.emacs) -- GitLab