I am trying to search backwards and find
[ but skip all square brackets within strings. I came across
(nth 3 (syntax-ppss)); but I can't figure out how to use it with
let in the following code:
(defun ext-ess-symbol-at-point-modified () "Return the name of a symbol to the left of \"[\"." (interactive) (save-excursion (let* ((cpoint (point)) (sbt0 (search-backward "[" 1 t)) (sbt1 (search-forward "]" cpoint t))) (if (and sbt0 (not sbt1)) (progn (goto-char (1- sbt0)) (message "%s" (buffer-substring (search-backward-regexp "^\\|[[:space:]]") sbt0))) (error "Could not find open square bracket \"[\"")))))
I would like something along the lines of
(let* ((cpoint (point)) (sbt0 (while (nth 3 (syntax-ppss)) (search-backward "[" 1 t)))
nil, so if you want to subsequently return something else you need to place the loop within some other construct, e.g.