zoukankan      html  css  js  c++  java
  • emacs quick open and jump file (or buffer) which name is current word

    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)
    



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

  • 相关阅读:
    Android Studio开发JNIproject
    POJ 3006 Dirichlet&#39;s Theorem on Arithmetic Progressions 快筛质数
    ZooKeeper是什么?
    android学习记录(十三)Task 和 Activity 回退栈操作。
    Java程序员的日常—— IOUtils总结
    sql基础知识:分页+排序
    Elasticsearch推荐插件篇(head,sense,marvel)
    sql基础知识:日期的常用用法
    [大数据之Spark]——Actions算子操作入门实例
    [大数据之Spark]——Transformations转换入门经典实例
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4820984.html
Copyright © 2011-2022 走看看