Is there anyway for me to set the default content of the scratch buffer in emacs?
So say, can i do something like this:
emacs <some option> "this is my default text" <ENTER>
This would open up emacs, and put "this is my default text" onto the buffer?
Put the following in your .emacs file: (setq initial-scratch-message "this is my default text")
(Response to comment:) If you want to make it dynamic, you could run the following from the command line: emacs --eval "(setq initial-scratch-message \"your message\")"
Related
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*") ))
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.
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"))))
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.
The scratch message always says:
;; 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.
How do I remove this and make the blank scratch message the default?
You can customize this variable 'initial-scratch-message to be whatever message you want.
(setq initial-scratch-message "")
For Emacs 23, you can do this:
(setq initial-scratch-message nil)
From the documentation: "Initial message displayed in scratch buffer at startup. If this is nil, no message will be displayed."
You can turn off the initial splash screen with
(setq inhibit-startup-message t)
this appears to also remove the initial message in the scratch buffer.