bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#20732: in-string-p fails


From: Andreas Röhler
Subject: bug#20732: in-string-p fails
Date: Fri, 05 Jun 2015 08:01:11 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0


Am 04.06.2015 um 23:06 schrieb Dmitry Gutov:
On 06/04/2015 02:50 PM, Andreas Röhler wrote:

In question slow is better than false.

Then (setq open-paren-in-column-0-is-defun-start nil) in your Emacs config.

There is no way to know reliably if inside a string than scanning the
whole buffer. All other is woodoo.

There's a whole package dedicated to doing is faster and in easier fashion: lisp/emacs-lisp/syntax.el.

You're welcome to suggest improvements that don't sacrifice performance to this extent.



Why not have two functions dealing with different circumstances.

- in-string-p-maybe, which might guess first and fast, re-fine afterwards.

- a precise in-string-p running parse-partial-sexp on widened buffer.

(defun in-string-p-precise ()
"Returns the character which delimits the string if inside, nil otherwise. "
  (save-restriction
    (widen)
    (ignore-errors (nth 3 (parse-partial-sexp (point-min) (point))))))

Maybe also return t if at string-start pos already:

(eq (char-syntax (char-after)) 34)

When not called from complex environment (also precise):

(defun ar-in-string-p ()
  "Return position, if inside or at opening delimiter.

Otherwise return nil. "
  (interactive)
  (save-restriction
    (widen)
    (let* ((pps (parse-partial-sexp (point-min) (point)))
       (erg (and (nth 3 pps) (nth 8 pps)))
       (la (unless erg (when (eq (char-syntax (char-after)) 34)
                 (point)))))
      (setq erg (or erg la))
      (when (interactive-p) (message "%s" erg))
      erg)))










reply via email to

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