1

我想在 using 处插入 kill-ring 的内容(yank),但是如果在被拉出的文本的开头有空格,则应在插入前将其删除。

如何才能做到这一点?

(我看过save-excursionre-search-backward无法让它工作)..

4

2 回答 2

2

你可以试试

(defun my-yank ()
  (interactive)
  (let ((start (point)))
    (call-interactively 'yank)
    (let ((end (point)))
      (save-excursion
        (goto-char start)
        (delete-region (point)
                       (progn (skip-chars-forward " \t" end) (point)))))))
于 2013-11-06T13:23:07.817 回答
1

这是一个可能的解决方案

(defun yank-no-spaces (&optional arg)
  (interactive "*P")
  (yank arg)
  (save-restriction
    (save-excursion
      (narrow-to-region (point) (mark))
      (goto-char (point-min))
      (just-one-space 0))))
于 2013-11-06T13:27:55.917 回答