加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何绑定密钥以在dired emacs中运行shell命令

发布时间:2020-12-15 18:24:05 所属栏目:安全 来源:网络整理
导读:当我在emacs中使用dired模式时,我可以按类型!xxx运行 shell命令,但是如何绑定一个键来运行此命令? 例如,我想在文件上按O,然后dired将运行’cygstart’来打开这个文件. 您可以使用shell命令功能.例如: (defun ls () "Lists the contents of the current di
当我在emacs中使用dired模式时,我可以按类型!xxx运行 shell命令,但是如何绑定一个键来运行此命令?
例如,我想在文件上按O,然后dired将运行’cygstart’来打开这个文件.
您可以使用shell命令功能.例如:
(defun ls ()
  "Lists the contents of the current directory."
  (interactive)
  (shell-command "ls"))

(global-set-key (kbd "C-x :") 'ls); Or whatever key you want...

要在单个缓冲区中定义命令,可以使用local-set-key.在dired中,您可以使用dired-file-name-at-point获取文件的名称.所以,要完全按照你的要求做:

(defun cygstart-in-dired ()
  "Uses the cygstart command to open the file at point."
  (interactive)
  (shell-command (concat "cygstart " (dired-file-name-at-point))))
(add-hook 'dired-mode-hook '(lambda () 
                              (local-set-key (kbd "O") 'cygstart-in-dired)))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读