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

问题描述 投票:0回答:2

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

  1. emacs / path / to / file ;;默认
  2. emacs / path / to / file ;;如果路径不存在,请创建它,然后创建文件
  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列

如果您在点文件中实现了相同的功能,可以在此处共享它,将不胜感激。

谢谢!

emacs filenames
2个回答
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)))))

0
投票

bash函数解析line和col参数呢?

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 }
© www.soinside.com 2019 - 2024. All rights reserved.