[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [FR] Support for spell checking of citation macros
From: |
Gustavo Barros |
Subject: |
Re: [FR] Support for spell checking of citation macros |
Date: |
Wed, 20 Nov 2019 11:36:09 -0300 |
User-agent: |
mu4e 1.2.0; emacs 26.3 |
Hi all,
On Tue, Nov 19 2019, Gustavo Barros wrote:
This is a feature request for adding support for spell checking of
citation
macros in AUCTeX. That is, to skip citation macros bibkeys while
spell-checking.
This is a follow up message, as I could finally reach better results for
the flyspell case, which I share.
#+begin_src emacs-lisp
(defun my/tex-flyspell-bibkey-p ()
"Returns non-nil if on a citation macro bibkey, nil otherwise."
(let ((macro (reftex-what-macro 1 (- (point) (* 10 fill-column))))
(pos (point))
(lastarg))
(and
(stringp (car macro))
(string-match
"\\`\\\\cite\\|cite\\([s*]\\|texts?\\)?\\'\\|bibentry"
(car macro))
(save-excursion
(goto-char (cdr macro))
(re-search-forward (regexp-quote (car macro))
(+ (point) (length (car macro))) t)
(while (and (my/reftex-move-to-next-citation-arg)
(> pos (point)))
(setq lastarg (following-char))
(forward-list 1))
(eq lastarg ?\{)))))
(defsubst my/reftex-move-to-next-citation-arg (&optional _ignore)
;; Just extends 'reftex-move-to-next-arg' to the parenthesis case
;; of biblatex qualified citation lists.
(cond
;; Just to be quick:
((memq (following-char) '(?\( ?\[ ?\{)))
;; Do a search
((and reftex-allow-detached-macro-args
(looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[
\t]*[([{]"))
(goto-char (1- (match-end 0)))
t)
(t nil)))
#+end_src
This function should handle the check whether we are at a bibkey or not
reliably without parsing the bibfiles. It also handles whitespace
between macro arguments in the same terms as RefTeX (that is, if you use
`reftex-allow-detached-macro-args'). The only case I could conceive
where this doesn't work is when the space comes between the macro name
and the *first* argument. That is, things will work with "\cite[See]
[34] {Foo2019}", but not with "\cite [See][34]{Foo2019}". But that's
because `reftex-what-macro' won't recognize the second case as a macro.
Anyway, this is enough of a corner case for me to be satisfied with
this.
If this is deemed decent, it might also be useful at
https://lists.gnu.org/archive/html/bug-auctex/2019-11/msg00007.html.
Best regards,
Gustavo Barros.