emacs: 文本输入中文件目录自动补全

2023-03-14,,

emacs: 文本输入中文目录自动补全

<!--
/*--><!--*/
html { font-family: Times, serif; font-size: 12pt; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color: #add8e6; font-weight:normal }
.target { }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right {margin-left:auto; margin-right:0px; text-align:right;}
.left {margin-left:0px; margin-right:auto; text-align:left;}
.center {margin-left:auto; margin-right:auto; text-align:center;}
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: courier, monospace;
font-size: 90%;
overflow:auto;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; }
th.right { text-align:center; }
th.left { text-align:center; }
th.center { text-align:center; }
td.right { text-align:right; }
td.left { text-align:left; }
td.center { text-align:center; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
div.inlinetask {
padding:10px;
border:2px solid gray;
margin:10px;
background: #ffffcc;
}
textarea { overflow-x: auto; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
-->

UP | HOME
 

emacs: 文本输入中文件目录自动补全

Table of Contents

1 引言
2 补全过程演示
3 实现代码

1 引言

由于在使用emacs进行文本处理过程以及数据处理的代码编写过程中, 经常需要输入对应的数据所在的目录以及文件名, 通常采用的方法就是直接进行输入, 但是由于用惯了vim中youcompleteme的文件名以及目录补全的功能, 总希望在emacs中也能够拥有类似的功能. 于是展开了进一步的思索, 发现在使用shell-mode的时候, 能够实现对于文件名的自动补全, 于是google了shell.el的实现代码, 发现文件的自动补全是基于comint.el的. 因此, 此处的实现是借用了里面的两个函数.

2 补全过程演示

使用快捷键 C-c k 进行补全

    /lib/cpp
    ./emacsAutoCompleteFileAndDir.org

3 实现代码

;; Use C-tab to autocomplete the files and directories
;; based on the two commands `comint-dynamic-complete-filename`
;; and `comint-dynamic-list-filename-completions` (defun atfd ()
(interactive)
(comint-dynamic-list-filename-completions)
(comint-dynamic-complete-as-filename)) (global-set-key ( kbd "\C-c k" ) 'atfd)

将上述代码加入到.emacs文件中或是.emacs.d/init.el中就能够实现上述的功能.

Date: 2014-04-12 Sat

Author: Zhong Xiewei

Org version 7.8.11 with Emacs version 24

Validate XHTML 1.0

emacs: 文本输入中文件目录自动补全的相关教程结束。

《emacs: 文本输入中文件目录自动补全.doc》

下载本文的Word格式文档,以方便收藏与打印。