From e389b55833efccf7a62c8769e7506bd9ce4a79dc Mon Sep 17 00:00:00 2001 From: Philippe Dosch <Philippe.Dosch@loria.fr> Date: Fri, 26 Apr 2024 11:25:54 +0200 Subject: [PATCH] =?UTF-8?q?odj-orj=20ajout=C3=A9,=20cr=C3=A9ation=20phil-m?= =?UTF-8?q?acros=20&=20refactoring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .emacs | 62 ++------------------------------- .lisp/phil-macros.el | 82 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 59 deletions(-) create mode 100644 .lisp/phil-macros.el diff --git a/.emacs b/.emacs index 560ddc9..290701c 100644 --- a/.emacs +++ b/.emacs @@ -1058,74 +1058,18 @@ ;; (ce qui permet d'ouvrir le nouveau folder à la place de l'ancien) (put 'dired-find-alternate-file 'disabled nil) -;; Pour les quotes de mail trop longues (via insert-kbd-macro) -(defun mailcut () - "Format lines from quoted mails." - (interactive) - (end-of-line) - (kill-line) - (when (re-search-forward "[ >]*" nil t) - (replace-match " " nil t)) - (just-one-space) - (end-of-line) - (gin-do-auto-fill)) +(use-package phil-macros) + ;; Au niveau du mapping, c'est un peu tricky. Je n'ai pas trouvé le ;; moyen d'ajouter la touche contrôle, l'idée initiale étant de binder ;; ça sur la touche µ. J'ai récupéré le code dans un buffer dans lequel ;; j'ai exécuté toggle-enable-multibyte-characters (il faut utiliser ;; 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 c") '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 s") 'snip-lines-mail) - -(defun cite-mail-part () - "Prefix each line in the region with '> '." - (interactive) - (save-excursion - (let ((begin (region-beginning)) - (end (region-end))) - (goto-char begin) - (while (< (point) end) - (beginning-of-line) - (insert "> ") - (forward-line 1))))) (global-set-key (kbd "M-s t") 'cite-mail-part) +(global-set-key (kbd "M-s o") 'odj-org) ;;; .emacs ends here (provide '.emacs) diff --git a/.lisp/phil-macros.el b/.lisp/phil-macros.el new file mode 100644 index 0000000..6227fb9 --- /dev/null +++ b/.lisp/phil-macros.el @@ -0,0 +1,82 @@ +;;; phil-macros.el -- Phil's Macros +;;; Commentary: +;;; Code: + +(require 'gin-mode) + +;; Pour les quotes de mail trop longues (via insert-kbd-macro) +(defun mailcut () + "Format lines from quoted mails." + (interactive) + (end-of-line) + (kill-line) + (when (re-search-forward "[ >]*" nil t) + (replace-match " " nil t)) + (just-one-space) + (end-of-line) + (gin-do-auto-fill)) + +(defvar phil-scissors ">8 --------------------------------------------------------------- 8<" + "String to insert in \\[scissors].") + +(defun scissors() + "Insert a line of SCISSORS in the buffer." + (interactive) + (insert phil-scissors) + (forward-line 1)) + +(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)))) + +(defun cite-mail-part () + "Prefix each line in the region with '> '." + (interactive) + (save-excursion + (let ((begin (region-beginning)) + (end (region-end))) + (goto-char begin) + (while (< (point) end) + (beginning-of-line) + (insert "> ") + (forward-line 1))))) + +(defun odj-org() + "Translate a text-based agenda to an org structure." + (interactive) + (save-excursion + (let ((begin (region-beginning)) + (end (region-end))) + (goto-char begin) + (while (< (point) end) + (beginning-of-line) + (if (re-search-forward "^\\([0-9]+[^ ]?\\) " nil t) + (replace-match "***" nil nil nil 1)) + (forward-line 1))))) + +(provide 'phil-macros) +;;; phil-macros.el ends here -- GitLab