如何在emacs的点处杀死引用的字符串? [英] How to kill a quoted string at point in emacs?

查看:110
本文介绍了如何在emacs的点处杀死引用的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在源文件
中杀死引用的字符串,而不必标记字符串和杀死区域
的开头,但只要将该点放在引用的字符串中的任何位置,然后按一个快捷方式。



我试图在elisp中编写一个函数,但我发现文件
需要从头开始解析点确定点是否在引号字符串内,并找到引用的字符串的边界(也处理\)...



但文件是已经被font-lock解析了
所以现在我可以找出我是否在引用的字符串中:

  defun inside-quoted-string?()
(interactive)
(print(find'font-lock-doc-face(text-properties-at(point)))))

但是如何获得字符串的边界?
font-lock知道它,因为它很好地突出显示在蓝色的,但如何获得?



编辑:
感谢您的答案我想出了这个代码,
正是我想要的 - 移动代码,而不选择区域,甚至
移动到代码开始。

 (defun kill-at-point()
删除引用的字符串或包含点
(interactive)
的列表(let((p (nth 8(syntax-ppss))))
(if(eq(char-after p)?\)
(progn
(goto-char p)
(kill-sexp))
(progn
(up-list)
(let((beg(point)))
(backward-list)
-region beg(point)))))))
(global-set-key(kbdC-,)'kill-at-point)
pre>

欢迎任何改进建议。

解决方案

比依靠font-lock,你可以使用底层的解析器的数据。 / code>(nth 8(syntax-ppss))。然后,您可以使用(forward-sexp 1)跳过字符串以查找其结尾。


I would like to kill a quoted string in a source file without having to mark the beginning of the string and kill-region, but just by placing the point anywhere inside the quoted string and pressing a shortcut.

I tried to write a function in elisp for this, but I figured out that the file would need to be parsed from the beginning up to point to determine whether the point is inside quoted string, and to find the bounds of the quoted string(also handle the \")...

But the file is already parsed by font-lock. So now I can find out if I'm inside quoted string:

(defun inside-quoted-string? ()
  (interactive)
  (print (find 'font-lock-doc-face (text-properties-at (point)))))

But how do I get the bounds of the string? font-lock knows it, since it nicely highlights it in blue, but how do I get it?

Edit: Thanks for the answers. I came up with this code that does exactly what I wanted - move code around without selecting region or even moving to beginning of code.

(defun kill-at-point ()
  "Kill the quoted string or the list that includes the point"
  (interactive)
  (let ((p (nth 8 (syntax-ppss))))
    (if (eq (char-after p) ?\")
    (progn 
      (goto-char p)
      (kill-sexp))
      (progn
    (up-list)
    (let ((beg (point)))
      (backward-list)
      (kill-region beg (point)))))))
(global-set-key (kbd "C-,") 'kill-at-point)

Any suggestions to improve it are welcome.

解决方案

Rather than rely on font-lock, you can use the underlying parser's data. The start of the string around point (if any) is available as (nth 8 (syntax-ppss)). You can then use (forward-sexp 1) to jump over the string to find its end.

这篇关于如何在emacs的点处杀死引用的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆