emacs: add prot-spell-french-punctuation command

This commit is contained in:
Protesilaos 2026-07-02 12:57:52 +03:00
parent c0cb7dba22
commit e7f01f70e3
No known key found for this signature in database
GPG key ID: 99BD6459CD5CA3EA
3 changed files with 78 additions and 2 deletions

View file

@ -111,7 +111,8 @@
(prot-spell-spell-dwim
prot-spell-change-dictionary
prot-spell-spell-dwim
prot-spell-change-dictionary)
prot-spell-change-dictionary
prot-spell-french-punctuation)
"prot-spell")
(prot-emacs-keybind global-map

View file

@ -9240,7 +9240,8 @@ Also see Jinx, which is most probably better than Flyspell: [[#h:7f027040-7cd1-4
(prot-spell-spell-dwim
prot-spell-change-dictionary
prot-spell-spell-dwim
prot-spell-change-dictionary)
prot-spell-change-dictionary
prot-spell-french-punctuation)
"prot-spell")
(prot-emacs-keybind global-map
@ -18902,6 +18903,43 @@ function. Then you can control the buffer's specifics via
(advice-add #'ispell-display-buffer :override #'prot-spell-ispell-display-buffer)
;;;; French punctuation
;; TODO 2026-07-01: Maybe extend the command to check for all sorts of
;; rules, in accordance with the Charte orthotypographique du Journal
;; officiel:
;; <https://www.legifrance.gouv.fr/contenu/Media/Files/autour-de-la-loi/legislatif-et-reglementaire/charte_typographique_jo_janvier_2021.pdf?__cf_chl_f_tk=YcOBi.sMMWmrN5FxCQMM8YDz.OyTC62mXKuZnjZ2rvs-1782901834-1.0.1.1-IzZmLEEkwksUf1sSm5dljuFqSZjDPjXfLMYkIdbOa.Y>.
;;
;; Though that is not a simple search+replace operation...
;;
;; For the following:
;;
;; «Lespace insécable permet déviter la séparation entre deux
;; éléments. Elle sutilisera, entre autres, à lintérieur des
;; guillemets français, au sein des nombres, après les dito, avec les
;; tirets dincise.»
(defvar prot-spell-french-grammar-replacements
'(("\\([^[:punct:][:space:]]\\)\\?" . "\\1 ?")
("\\([^[:punct:][:space:]]\\):" . "\\1 :")
("\\([^[:punct:][:space:]]\\);" . "\\1 ;")
("\\([^[:punct:][:space:]]\\)!" . "\\1 !")
("«\\([^[:punct:][:space:]]\\)" . "« \\1")
("\\([^[:punct:][:space:]]\\)»" . "\\1 »")
("\\([^[:punct:][:space:]]\\)%" . "\\1 %"))
"Add no-break space to relevant punctuation.")
;;;###autoload
(defun prot-spell-french-punctuation ()
"Apply the `prot-spell-french-grammar-replacements' across the buffer."
(interactive)
(save-excursion
(save-restriction
(widen)
(pcase-dolist (`(,target . ,replacement) prot-spell-french-grammar-replacements)
(goto-char (point-min))
(while (re-search-forward target nil t)
(replace-match replacement))))))
(provide 'prot-spell)
;;; prot-spell.el ends here
#+end_src

View file

@ -96,5 +96,42 @@ function. Then you can control the buffer's specifics via
(advice-add #'ispell-display-buffer :override #'prot-spell-ispell-display-buffer)
;;;; French punctuation
;; TODO 2026-07-01: Maybe extend the command to check for all sorts of
;; rules, in accordance with the Charte orthotypographique du Journal
;; officiel:
;; <https://www.legifrance.gouv.fr/contenu/Media/Files/autour-de-la-loi/legislatif-et-reglementaire/charte_typographique_jo_janvier_2021.pdf?__cf_chl_f_tk=YcOBi.sMMWmrN5FxCQMM8YDz.OyTC62mXKuZnjZ2rvs-1782901834-1.0.1.1-IzZmLEEkwksUf1sSm5dljuFqSZjDPjXfLMYkIdbOa.Y>.
;;
;; Though that is not a simple search+replace operation...
;;
;; For the following:
;;
;; «Lespace insécable permet déviter la séparation entre deux
;; éléments. Elle sutilisera, entre autres, à lintérieur des
;; guillemets français, au sein des nombres, après les dito, avec les
;; tirets dincise.»
(defvar prot-spell-french-grammar-replacements
'(("\\([^[:punct:][:space:]]\\)\\?" . "\\1 ?")
("\\([^[:punct:][:space:]]\\):" . "\\1 :")
("\\([^[:punct:][:space:]]\\);" . "\\1 ;")
("\\([^[:punct:][:space:]]\\)!" . "\\1 !")
("«\\([^[:punct:][:space:]]\\)" . "« \\1")
("\\([^[:punct:][:space:]]\\" . "\\1 »")
("\\([^[:punct:][:space:]]\\)%" . "\\1 %"))
"Add no-break space to relevant punctuation.")
;;;###autoload
(defun prot-spell-french-punctuation ()
"Apply the `prot-spell-french-grammar-replacements' across the buffer."
(interactive)
(save-excursion
(save-restriction
(widen)
(pcase-dolist (`(,target . ,replacement) prot-spell-french-grammar-replacements)
(goto-char (point-min))
(while (re-search-forward target nil t)
(replace-match replacement))))))
(provide 'prot-spell)
;;; prot-spell.el ends here