Rudolf Adamkovič Personal site


Edit string at point

Useful for editing e.g. SQLite (with -*- mode: sql -*-) embedded in Lisp 26.

(defun my-edit-string-at-point ()
  "Edit string at point in an indirect buffer."
  (interactive)
  (let* ((point (point))
         (outer-bounds (save-excursion
                         (unless (looking-at "\"")
                           (search-backward-regexp "\""))
                         (bounds-of-thing-at-point 'sexp)))
         (inner-bounds (cons (1+ (car outer-bounds))
                             (1- (cdr outer-bounds)))))
    (with-current-buffer
        (edit-indirect-region (car inner-bounds)
                              (cdr inner-bounds)
                              'display-buffer)
      (goto-char (- point (car outer-bounds))))))
(keymap-set prog-mode-map "C-c '" #'my-edit-string-at-point)

Footnotes

(26)

Before, I tried and failed with


© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.