🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.text.tex
Article #12057

Patch to ispell.el (was: ispell & latex2e)

#12057
From: Christoph Wedler
Date: Tue, 04 Jul 1995 00:00
155 lines
5989 bytes
Last month, I asked:

 CW> Is there a way for ispell (or for the emacs `ispell.el' package)

 CW> (1) to recognize the new latex2e commands, esp. `\documentclass',
 CW>     `\usepackage',... (it wants to correct the option `12pt',...)

 CW> (2) to define own environments not to be checked (e.g.\ if you
 CW>     define own math environments)

 CW> (3) to define (optional) parameters (for specific commands) not to
 CW>     be checked?

I changed `ispell.el' a bit (patch below)  and introduced two new user options.

If I wish that `ispell-region'

1. skips regions between `%[' and `%]'

2. ignores the text inside verbatim/verbatim* environments

3. ignore optional args and NO args for
   (a) the environments figure (NO=0) / tabular (NO=1)
   (b) the LaTeX commands (own def.) \infrule (NO=3), \infax (NO=2)

4. skip the region between \documentclass and \begin{document}

I set: (& use AucTeX)

(defun ispell-build-skip-regexp (nr)
  (concat "\\("
	  (mapconcat '(lambda (elem) (regexp-quote (car elem)))
		     (aref ispell-skip-alists nr)
		     "\\|")
	  "\\)"))

(setq ispell-skip-alists
      [
       nil
       (;;1
	("%[" . "%]")
	)
       (;;2
	("verbatim"	ispell-find-matching-end)
	("verbatim*"	ispell-find-matching-end)
	("figure"	ispell-tex-arg-end 0)
	("tabular"	ispell-tex-arg-end)
	)
       (;;3
	 ("infrule"		ispell-tex-arg-end 3)
	 ("infax"		ispell-tex-arg-end 2)
	 ("documentclass" .	"\\begin{document}")
	 )])

(setq ispell-skip-regexp
      (concat (ispell-build-skip-regexp 1)
	      "\\|\\\\begin{"
	      (ispell-build-skip-regexp 2)
	      "}\\|\\\\"
	      (ispell-build-skip-regexp 3)))

(defun ispell-find-matching-end (dummy)
  (condition-case nil
      (LaTeX-find-matching-end)
    (error (goto-char (point-max)))))

(defun ispell-tex-arg-end (dummy &optional arg)
  (condition-case nil
      (progn
	(while (looking-at "\\[") (forward-sexp))
	(forward-sexp (or arg 1)))
    (error (goto-char (point-max)))))

Here is the patch (using it without the `setq' above doesn't change the
functionality of `ispell.el')

diff -c /home/clstaff/wedler/emacs/orig/ispell.el.orig /home/clstaff/wedler/emacs/ispell.el
*** /home/clstaff/wedler/emacs/orig/ispell.el.orig	Tue Jul  4 12:00:19 1995
--- /home/clstaff/wedler/emacs/ispell.el	Tue Jul  4 11:42:04 1995
***************
*** 1606,1611 ****
--- 1606,1627 ----
  
  ;;; Spelling of comments are checked when ispell-check-comments is non-nil.
  
+ (defvar ispell-skip-regexp nil
+   "*Regexp for beginning of region not to be spell-checked, if non-nil.
+ If it matches, we determine the index IDX, which is the last used regexp
+ group (or 0 if none) and its corresponding text KEY (or the text matching
+ the whole regexp if IDX=0).  KEY is used as the key for the IDXs reference of
+ `ispell-skip-alists' to find the end of the region not to be spell-checked.")
+ 
+ (defvar ispell-skip-alists [(("%[" . "%]"))]
+   "*Vector of alists to find the end of the region not to be spell-checked.
+ Each association is of the form
+ (KEY . STRING) / (KEY . SYMBOL): end of region (eor) is the beginning
+ of the next occurence of STRING / the evaluated SYMBOL in the region.
+ (KEY STRING): eor is end of the next occurence of STRING in the region.
+ (KEY SYMBOL ARGS): call the function SYMBOL with the args KEY and all ARGS.
+ (KEY . ???) or no association: eor is end of line.")
+ 
  ;;;###autoload
  (defun ispell-region (reg-start reg-end)
    "Interactively check a region for spelling errors."
***************
*** 1631,1636 ****
--- 1647,1682 ----
  		(cond			; LOOK AT THIS LINE AND SKIP OR PROCESS
  		 ((eolp)		; END OF LINE, just go to next line.
  		  (forward-char 1))
+ 		 ((and ispell-skip-regexp
+ 		       (re-search-forward ispell-skip-regexp end t))
+ 		  (let ((idx (1- (/ (length (match-data)) 2))))
+ 		    (while (and (> idx 0) (not (match-end idx)))
+ 		      (setq idx (1- idx)))
+ 		    (let* ((limit (match-beginning 0))
+ 			   (key (buffer-substring (match-beginning idx)
+ 						  (match-end idx)))
+ 			   (adr (and (> (length ispell-skip-alists) idx)
+ 				     (cdr-safe
+ 				      (assoc key
+ 					     (aref ispell-skip-alists idx))))))
+ 		      (if (= limit start)
+ 			  (cond ((and adr (or (stringp adr) (symbolp adr)))
+ 				 (search-forward (eval adr) reg-end 'limit)
+ 				 (goto-char (match-beginning 0)))
+ 				((and (consp adr) (stringp (car adr)))
+ 				 (search-forward (car adr) reg-end 'limit))
+ 				((and (consp adr) (symbolp (car adr)))
+ 				 (apply (car adr) key (cdr adr)))
+ 				(t
+ 				 (beginning-of-line 2)))
+ 			(goto-char start)
+ 			;; Only check when "casechars" or math before comment
+ 			(if (or (re-search-forward ispell-casechars limit t)
+ 			      (re-search-forward "[][()$]" limit t))
+ 			    (setq string
+ 				  (concat "^" (buffer-substring start limit)
+ 					  "\n")))
+ 			(goto-char limit)))))
  		 ((and (null ispell-check-comments) ; SKIPPING COMMENTS
  		       comment-start	; skip comments that start on the line.
  		       (search-forward comment-start end t)) ; or found here.

Diff exited abnormally with code 1 at Tue Jul  4 13:22:46

I'm using
	LaTeX2e <1994/12/01>
	ispell 3.1.18
	XEmacs 19.11
		ispell.el, v.2.35
		AUC-TEX 9.2y

--
Christoph Wedler <wedler@fmi.uni-passau.de>
Technical Details
Message-ID: <WEDLER.95Jul4141526@vivaldi.fmi.uni-passau.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f9e16,84e6b1d9deaebd6b,start
X-Google-Attributes: gidf9e16,public
X-Google-Thread: 107729,84e6b1d9deaebd6b,start
X-Google-Attributes: gid107729,public
From: wedler@vivaldi.fmi.uni-passau.de (Christoph Wedler)
Subject: Patch to ispell.el (was: ispell & latex2e)
Date: 1995/07/04
Message-ID: <WEDLER.95Jul4141526@vivaldi.fmi.uni-passau.de>
X-Deja-AN: 105628866
distribution: world
followup-to: gnu.emacs.sources
organization: University of Passau, Germany
x-attribution: CW
newsgroups: comp.text.tex,gnu.emacs.sources