[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun proble
From: |
Alan Mackenzie |
Subject: |
Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] |
Date: |
Sun, 31 Dec 2017 10:50:05 +0000 |
User-agent: |
Mutt/1.7.2 (2016-11-26) |
Hello, Stefan.
On Sat, Dec 30, 2017 at 23:26:24 -0500, Stefan Monnier wrote:
> > + (if (nth 3 ppss) ; in a string
> > + start
> > + (when (nth 4 ppss) ; in a comment
> > + (setq ppss
> > + (parse-partial-sexp (point) eol nil nil ppss
> > 'syntax-table)))
> > + (catch 'got-it
> > + (while (< (point) eol)
> > + (setq start (point))
> > + (setq ppss (parse-partial-sexp (point) eol nil nil ppss t))
> > + (setq end (if (nth 4 ppss) (nth 8 ppss) eol))
> > + (goto-char start)
> > + (skip-syntax-forward "-" end)
> > + (when (< (point) end)
> > + (throw 'got-it (point)))
> > + (unless (forward-comment 1) ; comment straddles line break.
> > + (throw 'got-it nil))
> > + (setq ppss (syntax-ppss))))))))
> Why not use something like
> (>= (forward-comment (point-max)) (line-end-position))
> ?
Indeed. Why not just use beginning-of-defun--in-emptyish-line-p, which
is in the same file, in the same place as I coded
non-syntactic-ws-in-line, yet I failed to notice it? It is also
somewhat more elegantly coded than my new function.
However, beginning-of-defun--in-emptyish-line-p isn't quite right, in
that it fails to check whether BOL is inside a string. Something like
the following (untested) should fix it:
(defun beginning-of-defun--in-emptyish-line-p ()
"Return non-nil if the point is in an \"emptyish\" line.
This means a line that consists entirely of comments and/or
whitespace."
;; See https://lists.gnu.org/r/help-gnu-emacs/2016-08/msg00141.html
(save-excursion
(forward-line 0)
(let ((ppss (syntax-ppss)))
(and (null (nth 3 ppss))
(< (line-end-position)
(progn (when (nth 4 ppss)
(goto-char (nth 8 ppss)))
(forward-comment (point-max))
(point)))))))
Happy New Year!
> Stefan
--
Alan Mackenzie (Nuremberg, Germany).
- 26.0.90: mark-defun problem in c-mode, zhang cc, 2017/12/30
- Re: 26.0.90: mark-defun problem in c-mode, Eli Zaretskii, 2017/12/30
- Re: 26.0.90: mark-defun problem in c-mode, Alan Mackenzie, 2017/12/30
- beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Alan Mackenzie, 2017/12/30
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Eli Zaretskii, 2017/12/30
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Alan Mackenzie, 2017/12/30
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Alan Mackenzie, 2017/12/30
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Stephen Leake, 2017/12/30
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Alan Mackenzie, 2017/12/31
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode], Stefan Monnier, 2017/12/30
- Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode],
Alan Mackenzie <=