Subject: Re: bug#34233: 27.0.50; defvar in comment

From: Noam Postavsky <[email-masked]>
Date: Wed, 10 Jul 2019 07:49:43 -0400

Lars Ingebrigtsen <[email-masked]> writes:

> Michael Heerdegen <[email-masked]> writes:
>
>> This is `eval-sexp-add-defvars' not checking if defvars are really code.
>
> So is this the correct solution?
>
> diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
> index cb1b17b447..0e99cb9ac0 100644
> --- a/lisp/progmodes/elisp-mode.el
> +++ b/lisp/progmodes/elisp-mode.el
> @@ -1179,7 +1179,13 @@ eval-sexp-add-defvars
>            (let ((var (intern (match-string 1))))
>              (and (not (special-variable-p var))
>                   (save-excursion
> -                   (zerop (car (syntax-ppss (match-beginning 0)))))
> +                   (let ((syntax (syntax-ppss (match-beginning 0))))
> +                     ;; Top-level.
> +                     (and (zerop (car syntax))
> +                          ;; Not in a comment.
> +                          (null (nth 4 syntax))
> +                          ;; Not in a string.
> +                          (null (nth 3 syntax)))))
>                   (push var vars))))
>          `(progn ,@(mapcar (lambda (v) `(defvar ,v)) vars) ,exp)))))
>  
> (Those ppss things really should have accessors.  :-))

There is already a function for this particular case:
syntax-ppss-toplevel-pos.