Personal website Rudolf Adamkovič

Home / Emacs Packages / Edit Indirect


Edit string at point

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

(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:

1

Before, I tried and failed with

  • built-in narrowing, which breaks indentation and more,
  • built-in indirect buffers, which do not support fontification.

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