I would like to kill the quoted line in the source file without having to mark the beginning of the line and the kill area, but just placing a point somewhere inside the specified line and clicking on the shortcut.
I tried to write a function in elisp for this, but I realized that the file would need to be analyzed from the beginning to the point to determine if this point is inside the specified line and find the bounds of the quoted line (also process \ ") ...
But the file is already parsed using lock-lock. So now I can find out if I am inside the quoted string:
(defun inside-quoted-string? () (interactive) (print (find 'font-lock-doc-face (text-properties-at (point)))))
But how do I get the line bounds? font-lock knows about this 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 - to move the code without selecting a region or even go to the beginning of the 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 for improving it are welcome.
abo-abo
source share