blackball
blackball

Reputation: 748

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

I have following needs on opening file with Emacs:

  1. emacs /path/to/file ;; default
  2. emacs /path/to/file ;; if path doesn't exists, create it,then create the file
  3. emacs /path/to/file:15 ;; open file and goto line 15
  4. emacs /path/to/file:15:16 ;; open file and goto line 15 column 16
  5. emacs /path/to.file:15:16: ;; open file and goto line 15 column 16

If you have the same functionalities implemented in your dotfile, It will be greatly appreciated if you could share it here.

Thanks!

Upvotes: 0

Views: 185

Answers (2)

eMMe
eMMe

Reputation: 589

In elisp you can use a function like this, that you can put in your 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)))))

Upvotes: 1

eMMe
eMMe

Reputation: 589

What about a bash function parsing the line and col parameters?

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 }

Upvotes: 0

Related Questions