LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 902|回复: 7

emacs下如何实现这样的删除功能?

[复制链接]
发表于 2006-9-15 11:12:19 | 显示全部楼层 |阅读模式
就是要删除从光标处到下一个x字符(x代表任意字符)之间的所有内容.
以前在哪看到过,忘了记下来,现在找不到了.
发表于 2006-9-15 12:54:20 | 显示全部楼层
  1. (defun my-copy-to (to-char)
  2.   (interactive "c")
  3.   (save-excursion
  4.     (kill-ring-save
  5.      (point)
  6.      (or (search-forward (string to-char) nil t)
  7.          (point-max)))
  8.     (message "copyed text from this point to char `%c'" to-char)))
  9. (global-set-key (kbd "<f8>") 'my-copy-to)
复制代码
作为一个例子。按 F8 ,键入要 copy to 的 字符,就可以了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-15 14:45:30 | 显示全部楼层
谢谢
但我要的是删除功能,我改了一下
  1. (defun my-kill-to (to-char)
  2.   (interactive "c")
  3.   (save-excursion
  4.     (kill-region
  5.      (point)
  6.      (or (search-forward (string to-char) nil t)
  7.           (point-max)))
  8.     (message "killed text from this point to char `%c'" to-char)))
  9. (global-set-key (kbd "<f8>") 'my-kill-to)
复制代码
这样可以用了,但我不希望x也被删除,例如:现有字符串abcd,光标在a前,按f8d,abcd会被删掉,到我只想删除abc,把d留下,该怎么做?
不会elisp,搞了半天也没搞定
回复 支持 反对

使用道具 举报

发表于 2006-9-15 15:18:51 | 显示全部楼层
(- (search-forward (string to-char) nil t) 1)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-15 15:50:28 | 显示全部楼层
呵呵,多谢多谢
这样就可以用了
回复 支持 反对

使用道具 举报

发表于 2006-9-15 20:21:27 | 显示全部楼层
M-z
六个字……
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-15 22:59:37 | 显示全部楼层
Post by sssslang
M-z
六个字……

不错不错
  1. M-z runs the command zap-to-char
  2.    which is an interactive compiled Lisp function in `/usr/local/share/emacs/23.0.0/lisp/simple.elc'.
  3. It is bound to M-z.
  4. (zap-to-char arg char)

  5. Kill up to and [color="Magenta"]including[/color] arg'th occurrence of char.
  6. Case is ignored if `case-fold-search' is non-nil in the current buffer.
  7. Goes backward if arg is negative; error if char not found.
复制代码

可以exclude吗
回复 支持 反对

使用道具 举报

发表于 2006-9-16 01:11:47 | 显示全部楼层
不要神化自带的功能。
  1. (defun zap-to-char (arg char)
  2.   "Kill up to and including ARG'th occurrence of CHAR.
  3. Case is ignored if `case-fold-search' is non-nil in the current buffer.
  4. Goes backward if ARG is negative; error if CHAR not found."
  5.   (interactive "p\ncZap to char: ")
  6.   (if (char-table-p translation-table-for-input)
  7.       (setq char (or (aref translation-table-for-input char) char)))
  8.   (kill-region (point) (progn
  9.                          (search-forward (char-to-string char) nil nil arg)
  10. ;                         (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
  11.                          (point))))
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表