How can I invoke aquamacs from command line (OSX iterm) to open a file at a given line number?

1.1k Views Asked by At

I can invoke aquamacs from OSX iterm command line no problem.

aquamacs myfile.txt works as expected. However passing it a line number to open at does not work: aquamacs +22 myfile.txt also opens a new file called "+22" !!

How do I open a file at a particular line number? e.g with vi you can do vi +23 myfile.txt to open the file at line 23

2

There are 2 best solutions below

0
Tingfeng Xia On

I believe this is not supported by aquamacs. The command line aquamacs can only take in one argument which is the file name, and this is why you are creating a new file called "+22" when you do aquamacs +22 myfile.txt.

You may find this helpful.

0
nega On

As mentioned by @tingfengxia Aquamacs command line helper aquamacs is broken. (I believe it's fixed on trunk.)

aquamacs is basically a wrapper around macOS's open, so you can just do by hand what aquamacs is doing. Assuming you have Aquamacs.app properly installed

open -a Aquamacs myfile.txt --args +22

will do what you want. That is, open myfile.txt and move the cursor to line #22.

Note, that because of the way that open works, this will only work when starting a fresh Aquamacs session. If you already have Aquamacs running, and try do

open -A Aquamacs my_other_file.txt --args +39

Aquamacs will open my_other_file.txt in a new bufer, but it will not move to line #39. Any arguments will, in fact, be ignored.

I should add that Aquamacs does come with an associated emacsclient that works just fine. Provided you've run server-start in your Aquamacs session (either via your init file, or manually) you can then do

/Applications/Aquamacs.app/Contents/MacOS/bin/emacsclient -c +22 ~/myfile.txt

This will create a new GUI window (ie Aquamacs frame) associated with the current Aquamacs session, with myfile.txt loaded in its buffer, and the cursor at line #22. The full path to Aquamacs's emacsclient is obviously dependent on where you installed Aquamacs.