在 emacs 中自动转义拉出的字符串

Phi*_*ahn 2 emacs elisp

显然,这个周末我非常渴望向我的 Emacs 环境添加大量功能。我可以自己做一些基础知识,并寻找其他东西,但我一直无法找到解决方案(并且我对 Lisp 的了解不够好,无法自己完成)。

我经常使用 HTML 字符串,有时,如果我将它们从一个块移动到另一种块(或从一种语言移动到另一种语言),则字符串在未转义的地方会被破坏。所以,我想要一个执行类似操作的函数:

(defun smart-yank-in-string()
      (if (stringp) ; Check if the point is in a string
        ; Check if the region created from the point to the end of the yank ends the string 
        ; (and there is more yank left that isn't ";")
        ; Escape quotes for those locations recursively by prepending \
        ; Insert result into buffer @ mark
          ))
Run Code Online (Sandbox Code Playgroud)

有什么巧妙的想法吗?我认为它涉及使用kill-new存储变量并遍历它,但我对 elisp 不够熟悉来解决它。

And*_*ler 5

接下来的猛拉应该插入转义字符串:

(defun escape-doublequotes-at-car-of-kill-ring ()
  "Escape doublequotes in car of kill-ring "
  (interactive)
  (with-temp-buffer
    (insert (car kill-ring))
    (goto-char (point-min))
    (while (search-forward "\"" nil t 1)
      (replace-match "\\\\\""))
    (kill-new (buffer-substring-no-properties (point-min) (point-max)))))
Run Code Online (Sandbox Code Playgroud)