Opening file from filemanager as a full window - emacs

When opening a file in emacs using Window Explorer or GNOME Nautilus File, the file opened in split view and the bottom window contain the emacs welcome screen.
Is there any way that the file opens as a single window and remaining buffer like *scratch", message etc remains open but hidden.

Here's how to do it for Ubuntu:
Write to file /usr/local/share/applications/emacsclient.desktop:
[Desktop Entry]
Name=Emacsclient
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/local/bin/emacsclient %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=Emacs
Just make sure that emacsclient is indeed located in /usr/local/bin/emacsclient
(you can use which emacsclient in bash to see this).
Then execute from bash:
sudo update-desktop-database
Finally, add to your ~/.emacs:
(require 'server)
(or (server-running-p) (server-start))
After this, once an Emacs instance is running, clicking on a file in Nautilus
will open it in the current window of Emacs, without changing the window configuration.

If you want that behaviour permanently you can use:
(add-hook 'find-file-hook 'delete-other-windows)
in your emacs-initialization.

In general, the function display-buffer (or its related family of functions, e.g., pop-to-buffer) defaults to a split-window if no other settings control the window / frame selection. If you have further problems, one of your initial buffer choices is likely using something like that -- or you have a display-buffer-alist setting which is causing it.
Using (setq initial-buffer-choice t) will eliminate the Welcome screen and leave you with just a *scratch* buffer.
I use this in my Emacs setup file:
(setq initial-scratch-message nil)
(setq initial-buffer-choice t)
Depending upon whether you have desktop-save-mode active, you may need something like this also . . . I have modified the desktop-read function so that I can use it subsequent to the after-init-hook (which loads before the emacs-startup-hook).
(add-hook 'emacs-startup-hook (lambda ()
(bury-buffer "*scratch*") ))

Related

Make eshell tab completion behave like Bash

How can I make eshell autocomplete behave like Bash and Emacs in general i.e. it offers a list of choices rather than arbitrary selects one for you?
For example, if I have two directories "Download" and "Downloads", when I type "Down" and hit TAB, I expect another buffer pops up and shows me the choices. But eshell just completes it for me, i.e. if I press TAB, it completes to "Download"; hit TAB again, it changes to "Downloads".
Use this:
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
and
(setq eshell-cmpl-cycle-completions nil)
Both do as you ask and show a buffer listing the completions when I run my emacs as 'emacs -q' to avoid my own customizations. This is with emacs 23.3, are you running a much older version?
Also see http://www.emacswiki.org/emacs/EshellCompletion which is where I first went to check this out.
Steps to try this out:
Start emacs using 'emacs -q' as the command -- no other arguments.
Change to the *scratch* buffer
Paste or type in one of the above code snippets
Put your cursor at the end of the snippet and press 'C-e' to execute the code.
Start eshell
test
if neither one works, report back here with your version info and any other relevant details
You only need to have the following line:
(setq eshell-cmpl-cycle-completions nil)
eshell-mode automatically set pcomplete-cycle-completions to the value of eshell-cmpl-cycle-completions locally.

Opening normal buffer in emacs startup

When we launch emacs it opens welcome screen.
How to I open a normal buffer and so that I can continue writing (same as in gvim) and it prompt for saving it if it press the "X" close button.
Put this in your .emacs. I am no vi user but from your description I think this will do what you want.
(setq inhibit-startup-message t
initial-scratch-message nil
initial-buffer-choice "scratch")
Possibly you should look around adding the following code somewhere in your ~/.emacs:
(switch-to-buffer
(make-temp-name "temp"))
The main idea is to create a new buffer and switch immediately there.
make-temp-name() will generate a name for temporary buffer. Since it is not existent it will be created by switch-to-buffer().
Also you might want to have a fixed name of a new buffer, so you can just leave the following:
(switch-to-buffer "main")
You can also launch emacs with the --no-splash command argument (i.e. runemacs.exe --no-splash). Same effect and you don't need to modify the .emacs file if you are not comfortable in doing so.

specifying emacs startup behavior

I have got a question about config of emacs startup behavior. I don't have any idea about lisp, I simply love emacs for editing.
What I would like to have is the following:
I call emacs like emacs FILE
emacs opens a window entitled FILE
emacs splits the window horizontally
in the upper frame it opens a file FILE.abc
goes to the bottom frame and it opens FILE.xyz
optimally comes back to the upper frame
I had a look here:
how to create a specific window setup on in .emacs
and it's half way through. However, the macro thing doesn't really work in my case because I need to pass an argument. Any help greatly appreciated.
In general, you will find yourself better served by Emacs if you stay in it just "visit" (as Emacs has been - for 40 years - calling the operation elsewhere known - for 30 years - as "open") files.
Here is the function (untested):
(defun open-two-files (file)
"Open FILE.abc in the top window and FILE.xyz in the bottom window.
http://stackoverflow.com/questions/15070481/specifying-emacs-startup-behavior"
(interactive "FEnter file base name: ")
(let ((old-window (selected-window))
(new-window (split-window-below)))
(find-file (concat file ".abc"))
(select-window new-window)
(find-file (concat file ".xyz"))
(select-window old-window)))
You need to put it into your ~/.emacs.el.
Now, if you have emacs already opened, you need to do M-x open-two-files RET foo RET to open foo.abc and foo.xyz.
If you want to start a new Emacs session, type emacs --eval '(open-two-files "foo")'

How do I copy entire contents of file (>1 pane) in Tmux emacs copy mode?

i want to copy the entire contents of a file using emacs copy mode in tmux.
however when i enter copy mode, type C-space to start highlighting text, and then type M-> to jump to the end of the file, i end up just jumping to the file info section at the bottom of the tmux pane.
here's a pic showing what happens:
edit: i'm a new user and apparently can't post a pic yet. but basically you could imagine the yellow highlighted (selected) text in tmux copy mode. instead of the end of the file i can only highlight to the bottom of the pane (which looks kinda like this):
-u-:----F1 file_name.rb Top L1 (Ruby)---------------------------------
my question is, how can i enter copy mode, start selecting text, and jump to the end of the file?
and if this isn't the best way to accomplish my goal (of copying an entire file's contents while in tmux), what's a better way of doing it?
thx!
p.s.
i've followed the instructions here: https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
and also the instructions from the pragmatic tmux book.
in case it helps, here're the relevant lines from my .tmux.conf file (which i mostly copied from the pragmatic tmux book):
# use pbcopy|pbpaste wrapper script
set-option -g default-command "reattach-to-user-namespace -l zsh"
# send contents of current tmux buffer to system clipboard
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
# support pasting from the system clipboard
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste buffer"
# overriding "auto-detection" to always use emacs
set-option -g status-keys emacs
set-option -gw mode-keys emacs
The answer is yes and it’s pretty easy:
You need to run one of the tmux commands. You can run a tmux command by doing Ctrl+b+: and typing the command.
load-buffer path
or
loadb path
for short
tmux does not really understand that you are running emacs in the tty that it has provided. It only knows what has been written to that tty; so, when you press M-> while in tmux copy-mode, it simply moves to the bottom of the pane’s scrollback history (M-> while in copy-mode runs the (copy-mode-specific) tmux command history-bottom).
You really need to approach this problem from inside emacs. Here are some (interactively runnable) example functions that you could bind to key in emacs:
(defun write-region-to-tmux-buffer (beg end)
(interactive "r")
(shell-command-on-region beg end "tmux load-buffer -" nil nil nil t))
(defun write-buffer-to-tmux-buffer ()
(interactive)
(write-region-to-tmux-buffer (point-min) (point-max)))
If you want to bypass the buffer and use the file instead (i.e. create a buffer from the file on the disk, not the (possibly modified) contents of the buffer), you might use something like this:
(defun write-buffer-file-to-tmux-buffer ()
(interactive)
(let ((fn (buffer-file-name)))
(if fn
(shell-command
(concat "tmux load-buffer "
(shell-quote-argument fn)))
(error "Not a file-backed buffer"))))

Emacs: How do I stop "*Buffer List*" from showing when opening 3+ files

When I open 3+ files in emacs, I get a split window with one of my files in the upper buffer and Buffer List in the lower buffer.
How can I get emacs to NOT put Buffer List there, but instead show another one of my files.
thanks. -John
Try this:
(setq inhibit-startup-buffer-menu t)
Documentation can be found here.
Note: This option was introduced in Emacs 22.
For Emacs 21 and before, you could add the following workaround to your .emacs which will force Emacs to only have one window visible upon startup:
(add-hook 'after-init-hook 'delayed-delete-other-windows)
(defun delayed-delete-other-windows ()
"need the call to happen after startup runs, so wait for idle"
(run-with-idle-timer 0 nil 'delete-other-windows))