Sometime, we need to open a file or buffer which name begin with current word in emacs.

Here I give the solution as follows.

;; -----------------------------------------------------------------------------
;; quick-file-jump.el
;; Why this module?
;; Sometimes, we need to open a file or buffer which name
;; began with current word in emacs.
;; Here is the solution.
;;
;; Install.
;; put this file (quick-file-jump.el) in your load path and
;; add follow codes into your initial emacs files (.emacs or init.el)
;; (require 'quick-file-jump)
;; (global-set-key (kbd "<M-return>") 'ab/quick-buffer-jump)
;;
;; Author:
;; Aborn Jiang (aborn.jiang@foxmail.com)
;; 2014-05-13
;; ----------------------------------------------------------------------------- (provide 'quick-file-jump)
(defun ab/quick-buffer-jump ()
"Quickly jump to buffer/file which name is current word"
(interactive)
(setq fname (current-word))
(setq blist (buffer-list))
(setq status nil)
(setq switchedbuffer "nil")
(dolist (value blist)
(when (and (bufferp value)
(buffer-file-name value)
(not status)
(string-match (concat "^" (regexp-quote fname))
(buffer-name value)))
(progn (switch-to-buffer (buffer-name value))
(setq status t)
(setq switchedbuffer (buffer-name value)))
))
(if status ;; success search in buffer list.
(message "skip to %s buffer" switchedbuffer)
(ab/quick-file-jump))) ;; find files in current path. (defun ab/quick-file-jump ()
"Quickly open and jump file with name begin with current word"
(interactive)
(setq fname (current-word))
(setq switchedfile "nil")
(setq dflist (directory-files (ab/get-current-path)))
(dolist (value dflist)
(when (and (file-regular-p value)
(string-match
(concat "^" (regexp-quote fname)) value))
(find-file value)
(setq switchedfile value)
(setq status t)))
(if status ;; success search in file list
(message "open and skip to %s file." switchedfile)
(message "not find file name begin %s" fname))) (defun ab/get-current-path ()
"Get the current path"
(interactive)
(message (file-name-directory (buffer-file-name)))) ;; default global key setting
(global-set-key (kbd "<M-return>") 'ab/quick-buffer-jump)

版权声明:本文博主原创文章,博客,未经同意不得转载。

emacs quick open and jump file (or buffer) which name is current word的更多相关文章

  1. [daily] emacs显示file name buffer的全路径

    在用emacs看代码的时候,在文件间跳来跳去,如果工程太大的话,很可能会有重名文件,这个时候, 你就不知道自己在什么的地方了.需要一个查看当前正在编辑区的文件的名字的方法. emacs在这个地方,存储 ...

  2. linux 下 Emacs dired 模式 隐藏 dot file ".filename" 文件

    有时候 emacs 下调用 C-x dired 是挺方便的一个事,但是一堆的点文件(linux下以"."为前缀的文件,即隐藏文件)让人目不暇接,打算隐藏之. 参考如下: 最主要的是 ...

  3. 关于之前玩emacs记的些笔记

    移动 C-v 向前翻页 M-v 向后翻页 C-l 当前行居中显示 继续按会依次到上,下,中   C-x C-c 退出 C-g    退出一个正在运行的命令,还可以取消数字参数和只输入到一半的命令   ...

  4. emacs 操作集锦

    1.C-k 的功能并不是剪切当前行,而是剪切当前行从光标到行末的内容. Emacs 中的剪切不叫剪切(cut),叫kill,复制(copy)不叫copy ,叫kill-ring-save (这个可以理 ...

  5. Emacs Lisp 功能扩展集锦

    http://docs.huihoo.com/homepage/shredderyin/emacs_elisp.html Emacs 具有超强的扩展性.这是当今没有任何其它编辑器可以比拟 的强大特点. ...

  6. GNU Emacs命令速查表

    GNU Emacs命令速查表 第一章  Emacs的基本概念 表1-1:Emacs编辑器的主模式 模式 功能 基本模式(fundamental mode) 默认模式,无特殊行为 文本模式(text m ...

  7. NASM mode for Emacs

    NASM mode for Emacs   Quick post for those Emacs users out there.   The common assembler used on GNU ...

  8. Emacs 快速指南(中文翻译)

      Emacs 快速指南 目录 1. 小结(SUMMARY) 2. 基本的光标控制(BASIC CURSOR CONTROL) 3. 如果 EMACS 失去响应(IF EMACS STOPS RESP ...

  9. Emacs快速入门

    Emacs 快速入门 Emacs 启动: 直接打emacs, 如果有X-windows就会开视窗. 如果不想用X 的版本, 就用 emacs -nw (No windows)起动. 符号说明 C-X ...

随机推荐

  1. .NET垃圾回收笔记

    名词 垃圾收集目标 ephemeral GC 发生在Gen 0 和Gen 1 的垃圾收集 Full GC 发生Gen 2 及以上的Gen与LOH的垃圾收集 垃圾收集模式 工作站模式 GC直接发生在内存 ...

  2. Oracle SQL Lesson (3) - 使用单行函数自定义输出

    大小写转换函数LOWER('SQL Course') = sql courseUPPER('SQL Course') = SQL COURSEINITCAP('SQL Course') = Sql C ...

  3. HDU 4982 Goffi and Squary Partition(推理)

    HDU 4982 Goffi and Squary Partition 思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no.注意构造时候的推断,因为 ...

  4. wbadmin delete backup删除服务器旧的镜像备份

  5. python进阶八_警告和异常

    心情有点纠结,怎么说呢,倒不是由于其它学习上的事情,反而是由于生活上狗血的剧情逼着人偏离,渐行渐远,人跟人之间有误会也是正常的,可能是由于交流不够,彼此不够了解吧,希望能尽快度过这一段纠结的日子,简单 ...

  6. Unity 捕获IronPython脚本错误

    using System; using System.Collections.Generic; using System.IO; using System.Reflection; using Syst ...

  7. android数据访问模式:档、SharedPreferences

    android数据访问模式:档.SharedPreferences.SQLite 数据库.Content provider 文件流: 使用java IO流对文件进行读写操作,文件权限默认. 指定文件权 ...

  8. 懒与馋的平衡:餐饮O2O市场广阔,发展不易

    餐饮行业是众多行业中O2O起步较早的,现在方兴未艾的团购站点中最先涉足的领域就有餐饮版块.长时间的合作推广,很多餐饮商家已经从中尝到甜头,可以说餐饮行业市场基础培育的比較好,所以餐饮O2O 已经是大势 ...

  9. hdu 1171 Big Event in HDU(母函数)

    链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...

  10. iis6开户gzip 网站属性里面没有服务选项卡

    请注意一点,是直接在名为“网站”的文件夹上面右键选择属性,不是去点下面建立的某一个网站.开户GZIP是整台服务器上面的虚拟主机都同时开启的,不对针某一个单独网站. 开启Gzip具体步骤: 1. 在 & ...