Opening normal buffer in emacs startup - emacs

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.

Related

Opening file from filemanager as a full window

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*") ))

What is the alternative to find-file-hook when buffer file already exists?

I have a series of functions that execute normally when a file is opened or when a particular mode is activated. The find-file-hook doesn't get triggered if the file is already open, when I try to open a file that is already open (e.g., in another frame), Emacs correctly switches to that buffer. However, under that scenario my custom functions do not activate because there is no trigger. I don't think the standard hooks cover a situation like this one.
What is the alternative, to find-file-hook when a buffer file already exists?
I'd try to use advice for this. You can tell whatever find-file command you use to make sure your tabbar is set up correctly. Simple example, since I use ido-find-file:
(defun my-find-file ()
(interactive)
(call-interactively 'ido-find-file))
(defadvice my-find-file (after do-something)
(message "doing stuff"))
(ad-activate 'my-find-file)
If this does not happen very often, you could just reopen the file to trigger the find-file-hook. To do so, just type C-x C-v <enter>.

How to open an org-mode file automatically in Emacs

How to open files automatically when starting emacs? does not work either under Windows or under Linux.
After adding the find-file command I received a message
so I disabled the auto-save, but the file does not load anyway.
(add-to-list 'load-path "~/emacs/org-8.0.3")
(setq auto-save-default nil)
(find-file "/home/uwe/Dropbox/orgmode.org")
You probably want to set the initial-buffer-choice variable so that it switches to your org file after running your init.el.
(setq
org-default-notes-file "/home/uwe/Dropbox/orgmode.org"
initial-buffer-choice org-default-notes-file)
The message you see proves that the file is indeed loaded just fine. All it tells you is that there's some auto-save file left over, indicating that some edits were not saved last time. You can ignore the message (which is not an error message), or you can use M-x recover-this-file RET to recover the unsaved changes from the auto-save file.
I strongly recommend you don't disable auto-saving.
IOW what you think doesn't work (automatically loading orgmode.org) actually does work. The only thing that doesn't work the way you want is that this file is not displayed and instead the *scratch* buffer is displayed. The reason for this depends on how you started Emacs. And the fix for it depends on all the different ways you might start Emacs (e.g. if you only ever start Emacs in the exact same way, it's easier).
Don't disable the auto-save, it could save ours files.
Anyway, delete #orgmode.org, if the diff between the two file don't interest you.

How to make Emacs start in `text-mode` and get rid of LISP message?

How can I make Emacs start in text-mode and get rid of the following message?
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
To get rid of the start message just set the initial-scratch-message variable to ""
(setq initial-scratch-message "")
To start the scratch buffer in text mode you will want to initial-major-mode variable
(setq initial-major-mode 'text-mode)
For setting of auto-mode when you start a specific major-mode you'll want to add an event to the mode hook
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Rather than fiddle with the way the scratch buffer works, I'd recommend you open Emacs with a file argument. E.g. if you do "emacs foo.txt" chances are it will already start up in text-mode without you having to do anything special for it.
You only do M-x text-mode in the scratch buffer.
That's all.

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))