删除Emacs中kill-ring开头的空格

时间:2013-11-06 12:23:11

标签: emacs elisp

我想使用(yank)在点处插入kill-ring的内容,但是如果在yanked文本的开头有空格,则应在插入之前将其删除。

如何做到这一点?

(我查看了save-excursionre-search-backward,但无法让它发挥作用)..

2 个答案:

答案 0 :(得分: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)))))))

答案 1 :(得分: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))))