Emacs open / path / to / filename:xx:yy

时间:2018-04-14 02:46:25

标签: emacs elisp dot-emacs

我对使用Emacs打开文件有以下需求:

  1. emacs / path / to / file ;;默认
  2. emacs / path / to / file ;;如果path不存在,则创建它,然后创建文件
  3. emacs / path / to / file:15 ;;打开文件并转到第15行
  4. emacs / path / to / file:15:16 ;;打开文件并转到第15行第16栏
  5. emacs /path/to.file:15:16:;;打开文件并转到第15行第16栏
  6. 如果您在dotfile中实现了相同的功能,如果您可以在此处分享,我们将不胜感激。

    谢谢!

2 个答案:

答案 0 :(得分:1)

在elisp中你可以使用这样的函数,你可以放入init.el

(let ((file-to-open (split-string (second command-line-args) ":")))
 (progn
   (find-file (first file-to-open))
   (if (>= (length file-to-open) 2)
     (progn (goto-char (point-min))
           (forward-line
            (- (string-to-int (second file-to-open)) 1))))
   (if (= (length file-to-open) 3)
    (forward-char
     (- (string-to-int (third file-to-open)) 1)))))

答案 1 :(得分:0)

解析line和col参数的bash函数怎么样?

function myemacs { if echo $1 | grep -q ":" ; then COL=$(echo $1 | cut -d: -f3); emacs $(echo $1 | cut -d: -f1) +$(echo $1 | cut -d: -f2):${COL:-0}; else emacs $1; fi }
相关问题