Emacsclient won't open file buffer directly in new frame from CLI - emacs

Sometimes it's nice to pop up Emacs (v 25.1.1) in a new frame to edit
a file I've specified in my shell. E.g., I'm using
% emacsclient --create-frame .../path/to/file.txt &
to attempt to create a frame with file.txt as the buffer.
According to emacsclient --help, this should work.
The problem is that Emacs just opens up a new frame with some other
buffer it's already working with (or no buffer if server wasn't running), rather than file.txt. Is this
just an emacsclient bug, or do I need to use some other invocation
to put the CLI-specified file into the new frame.
Yes, I can C-x b file.txt to select it since it's now an active
buffer, but that defeats the point of the CLI convenience (which is
actually a little alias, e).

Related

How to prevent a fram show up for a second when emacsclient or `emacs -nw` starts?

I am using emacs-daemon. When every I restart my daemon and do C-x C-b my Buffer List seems always full.
Later, when I start my emacsclient for a seconds(like a fast flash) it shows a file that located on the top of my Buffer List and opens the file I want to open. This is little annoying to face with all the time.
Example:
I type emacsclient -t file_a.py.
For a second or less, buffer called file_b.py opens (my lastly opened file).
Than file_a.py get opens.
This always repeats itself even I clean my buffer list doing following and open a new file (since buffer list now contains more than one file):
Link:
Edit: There's also the boring old buffer menu you get with C-x C-b.
In this menu, you can hold d until it marks each buffer for deletion,
then press x to commit.
Even after doing this after that IBuffer shows up since it is the latest opened buffer.
[Q] Is it possible to prevent 1 second file show up when I start emacsclient? If possible I always want to keep my Buffer List empty, but not sure would it be a good idea, or some how keep a empty file at the top of the buffer list since it will show a blank frame.
This also occurs when I using emacs -nw where scratch* buffer or latest opened buffer shows up for as seconds as well.

Emacsclient keep buffers after closing

In emacsclient, is there a way to open a file from the command line such that its buffer will remain open on the server after I close the client?
Alternatively, is there a command I can run from in a client to tell it to effectively detach from a buffer, so that the buffer does not get killed when the client exits?
Normally when closing emacsclient either with C-x C-c or C-x #, the buffer(s) associated with that client get killed, which is usually convenient behavior, but sometimes I would like for buffers to stay alive after closing. So far the only way I have found to accomplish this is to run the client without specifying any files, then visit them with C-x C-f, but I'm wondering if there's a better way to do this.
You should be able to do this by using the -n option. That means that it won't wait for you to "finish" the buffer and it'll just stay in the buffer list. I use this with emacsclient myself.
So, one option is to use emacsclient's eval command line option to run a lisp command to find the file you want.
emacsclient -c -e '(find-file "my_file")'
Obviously this is a lot more to type than the command sequence emacsclient -c, C-x C-f, my_file, but it could pretty easily be wrapped in a script that takes an extra argument to tell it whether to just choose the file or use find-file.
Someone more well versed in elisp than I could probably just add the option directly into emacs.
According the info manual, if you never want to kill emacsclient buffers, when you're done with them, you can customise the server-kill-new-buffers variable (more information at C-h v server-kill-new-buffers).
For you use-case, depending on how often you want the buffers killed or not, you could set the above variable to nil and then manually kill the buffers that you do want killed.

Open file from Emacs terminal without find-file

If I'm in a term-mode buffer and there is a file path displayed, how would I go about making the path "clickable", opening the file in a new buffer? It doesn't have to be mouse-clickable, in fact I'd prefer a key binding that works when the point is on the file path. Other than the common case of using ls, this function could be used when viewing a log file. Some debug info contains the file path and line number. Something like lib/library.rb:34 for example. Ideally, Emacs could open a new buffer and move the cursor to line 34.
The short answer is: don't work against Emacs. Let Emacs work for you.
While you can use find-file-at-point or put together something yourself, you will be much better off running make, grep and other stuff which prints "dir/file:pos" using M-x compile or M-x grep.
If you need to interact with your program which prints "dir/file:pos", you can pass a prefix argument to compile and the compilation buffer will be interactive.
If you have an arbitrary program whose output starts with "dir/file:pos", e.g., rails server, all you need to do is run it as (grep "rails server").

How to make emacsclient open each file in a separate 'window' within the same 'frame'

I am trying to open two files, say 'hello.txt' and 'world.txt' in emacsclient from a terminal and I want them to be opened in two different windows(as in the emacs sense of the word) but in the same frame.
I invoke emacsclient like this:
emacsclient -nw hello.txt world.txt
What presently happens is that a single emacsclient frame shows a single window where hello.txt is displayed. The other file, is opened into a buffer which is not visible.
If I instead use emacs instead of emacsclient I get the intended result(i.e two files get opened within the same frame but in two windows). How can I make emacsclient behave the same way as emacs?
I am not asking for ways to make emacsclient spawn multiple frames, rather I was asking for some way to make emacsclient to open multiple files in split-windows inside the same frame.
It doesn't seem like you can do this directly using emacsclient and a file list
You can achieve the same effect, with a bit of a kludge, by passing lisp to emacsclient to do what you want, although it gets a bit verbose
emacsclient -t -e '(progn (find-file "file1")(find-file-other-window "file2"))'
You perhaps could wrap this is a little shell script ec2files.sh, that takes two parameters and interpolates them into that lisp form.
Or write a defun that you load in emacs init that takes 2 file arguments and opens them.
(defun example-split-window-2-files (f1 f2)
(find-file f1)
(find-file-other-window f2))
and then invoke that from emacsclient -e
emacsclient -t -e '(example-split-window-2-files "file1" "file2")'
The variable server-window is what you want to look at. You can set this variable to a function that chooses which window to open.
I have the following in my emacs config:
(setq server-window 'pop-to-buffer)
That ensures that when you open a (single) file it uses another window (creating it if necessary) to display the file. You will need to either find or write a function to pass to server-window that will keep creating new windows for you to display files in.
Section 37.1, "Invoking `emacsclient'", of the emacs 24.3.1 manual says:
You can also force emacsclient' to open a new frame on a graphical
display, or on a text terminal, using the-c' and `-t' options.

Perl debugger on Emacs: Clear screen (buffer)?

Say I have long debugging session in Perl with perldb on Emacs (M-x perldb). The output piles up, and at some point it becomes difficult to navigate through it.
I can restart the debugger with R, but that doesn't clear up the previous output. Is there a command to clear up the output of the buffer of the Perl debugger without having to kill the debugger and starting a new session?
You can run comint-truncate-buffer. This will remove all but the last 1024 lines from the buffer. The size can be customized by changing comint-buffer-maximum-size.
If you'd like to have the buffer truncated automatically, run this snippet of elisp:
(add-hook 'comint-output-filter-functions 'comint-truncate-buffer)
Debugger input and output is buffer contents like any other — if you want to delete it, just do it. For example, C-x h C-w (mark-whole-buffer followed by kill-region) works in perldb buffers just fine, and is the closest equivalent to a "clear screen" command in a text terminal.