emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ispell: Skipping part of text in texinfo-mode


From: Arash Esbati
Subject: Ispell: Skipping part of text in texinfo-mode
Date: Thu, 29 Aug 2024 18:25:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Hi all,

I wanted to spellcheck a .texi file with 'M-x ispell RET' (running
hunspell) and it occurred to me that skipping part of text like in .tex
files isn't available OOTB.  In my experiment, ispell didn't ignore
anything and checked every Texinfo macro.

Having no clue about ispell.el, I managed to ease the pain with this
change:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 99f9e10a5a8..af12c99ce0a 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -1744,6 +1744,36 @@ ispell-html-skip-alists
  (e.g. \"<[tT][tT]/\" and \"<[^ \\t\\n>]\").")
 (put 'ispell-html-skip-alists 'risky-local-variable t)

+;;;###autoload
+(defvar ispell-texinfo-skip-alists
+  (let ((single-arg (regexp-opt '("acronym" "cite" "code" "command" "env"
+                                  "file" "key" "option" "url" "var")
+                                "@\\(?:"))
+        (skip-line (regexp-opt '("deffn" "defun" "defopt" "defvar"
+                                 "findex" "vindex" "kindex" "cindex"
+                                 "end "
+                                 "ifclear" "ifset" "include"
+                                 "setfilename" )
+                               "^@\\(?:")))
+    `(;; Macros with a single arg
+      (,single-arg ispell-tex-arg-end)
+      ;; Special arrangement for things like @kbd{C-(}
+      ("@\\(?:kbd\\|samp\\){" . "[^@]}")
+      ;; Envs to skip entirely
+      ("^@\\(?:\\(?:small\\)?example\\|lisp\\|verbatim\\)" .
+       "^@end \\(?:\\(?:small\\)?example\\|lisp\\|verbatim\\)")
+      ;; macros w/o arg
+      (,skip-line forward-line)
+      ;; This is for the first line:
+      ("\\\\input" forward-line)
+      ;; All other macros
+      ("@[a-zA-Z]+")))
+  "Lists of start and end keys to skip in texinfo buffers.
+Same format as `ispell-skip-region-alist'.
+Note - Match for general texinfo macros like @foo must come last, e.g.:
+  (\"@[a-zA-Z]+\").")
+(put 'ispell-texinfo-skip-alists 'risky-local-variable t)
+
 (defvar-local ispell-local-pdict ispell-personal-dictionary
   "A buffer local variable containing the current personal dictionary.
 If non-nil, the value must be a string, which is a file name.
@@ -1799,11 +1829,11 @@ ispell-accept-output
 and pass it the output of the last Ispell invocation."
   (if ispell-async-processp
       (if (process-live-p ispell-process)
-       (let ((timeout (if timeout-msecs
-                         (+ (or timeout-secs 0) (/ timeout-msecs 1000.0))
-                       timeout-secs)))
-        (accept-process-output ispell-process timeout))
-       (error "No Ispell process to read output from!"))
+          (let ((timeout (if timeout-msecs
+                            (+ (or timeout-secs 0) (/ timeout-msecs 1000.0))
+                          timeout-secs)))
+           (accept-process-output ispell-process timeout))
+        (error "No Ispell process to read output from!"))
     (if (null ispell-process)
        (error "No Ispell process to read output from!")
       (let ((buf ispell-output-buffer)
@@ -3277,6 +3307,8 @@ ispell-begin-skip-region-regexp
           ;; tex
           (if (eq ispell-parser 'tex)
               (ispell-begin-tex-skip-regexp))
+          (if (eq ispell-parser 'texinfo)
+              (ispell-begin-skip-region ispell-texinfo-skip-alists))
           ;; html stuff
           (if ispell-skip-html
               (ispell-begin-skip-region ispell-html-skip-alists))
@@ -3341,6 +3373,9 @@ ispell-skip-region-list
              skip-alist (append (car ispell-tex-skip-alists)
                                 (car (cdr ispell-tex-skip-alists))
                                 skip-alist)))
+    (if (eq ispell-parser 'texinfo)
+        (setq case-fold-search nil
+              skip-alist (append ispell-texinfo-skip-alists skip-alist)))
     (if ispell-skip-html
        (setq skip-alist (append ispell-html-skip-alists skip-alist)))
     (if (and ispell-checking-message
--8<---------------cut here---------------end--------------->8---

I presume there are some .texi writers here and I'd like to know how
others handle this.  Is the change above useful for ispell.el?
Otherwise I can put it in my init file and add it locally to
`ispell-skip-region-alist' in `texinfo-mode'.

Best, Arash



reply via email to

[Prev in Thread] Current Thread [Next in Thread]