ICON names the image, DEF is the key definition and KEY is a symbolįor the fake function key in the menu keymap. (defun tool-bar-local-item-pre (icon def key map after_item &rest props) (let ((buf (generate-new-buffer "untitled"))) You can try the following snippet, just add it to your. Emacs: Problems of the Scratch Buffer Xah Lee.Change variable initial-major-mode if you want the new buffer to have another mode on start.
I think it is intuitive for it to also ask, when you close a modified untitled buffer, therefore see my solution on how to upgrade kill-buffer to prompt before closing a modified buffer.ĮrgoEmacs revamps the default keybindings completely and has new-empty-buffer bound to Ctrl+N, like in almost all software. It also prompts only when you exit Emacs. The variable buffer-offer-save resets every time you change a major mode, therefore you need to annotate it with permanent-local. (put 'buffer-offer-save 'permanent-local t) (switch-to-buffer (generate-new-buffer "untitled")) You can implemented like this: (defun new-empty-buffer () That's how ErgoEmacs solves it, buy creating a new-empty-buffer command.
Emacs is a customizable editor, so you can and should create whatever workflow is comfortable for you. And I don't buy the argument that “this is how you do it in Emacs”. Drew's traditional solution seems too sub-optimal. Also, if you close *scratch* buffer, it doesn't ask you to save it, so you can accidentally lose all your work.
*scratch* is set to Lisp Interaction mode, but if I want to quickly evaluate some Elisp code, I could eval it running eval-expression ( Alt+:) or in Elisp interpreter IELM ( Alt+x Enter ielm).
Or you manipulate a snippet of text or code, but you don't want to change the original buffer, so you just copypaste it to a new temporary buffer. For example, you write quick notes or thoughts in several different buffers to keep trace of them-later you decide if you throw them away or save them. In every other text editor or word processor the intuition is to create a “new file” or a “new buffer”, not to switch to idiosyncratic *scratch* buffer. Otherwise (for C-x b) you need to put the buffer in the mode you want.īuffer *scratch* is by default in Lisp-Interaction mode, which is similar to Emacs-Lisp mode (but not the same). Why would you want to use C-x C-f instead of C-x b, if you might not want to save the buffer? Providing a file extension in the file name you give automatically puts the buffer in the proper major mode (typically). In this case, if you use C-x C-s then Emacs prompts you for the file location to save the buffer in. Giving it a new name (not the name of an existing buffer) creates a new buffer. You are (even here) prompted for the buffer name. If you don't want to take the chance of accidentally hitting C-x C-s and thus saving your edits, then use C-x b instead of C-x C-f. Or use C-x d to put yourself in a Dired buffer for the directory. Or just do it by editing the directory part when you first use C-x C-f. To change directories, you can use M-x cd. Note that you can first put yourself in a directory whose contents you don't care about, so that if you accidentally do save the buffer there then you can easily find, recognize and toss the file. Do not use C-x C-s to save the buffer to the file (i.e., to disk). Use C-x C-f, giving the (to-be-file-visiting) buffer a name. "If buffer too large and my cause performance issue."Īfter Emacs split long lines - it is possible to enable many *-modes and re-indent code.Not what you wanted to hear, but this is the Emacs way. (setq line-number-display-limit-width 200) In order to make such operation possible I add: (setq line-number-display-limit large-file-warning-threshold) I usually unroll long lines and indent by tags (like HTML, XML, JSON). If you need to work with really large files, you can use the View Large Files package which allows "viewing, editing and searching in large files in chunks." After requireing the package open large files with M-x vlfi. Obviously adjust the threshold value as you see fit. (add-hook 'find-file-hook 'my-find-file-check-make-large-file-read-only-hook) "If a file is over a given size, make the buffer read only." (defun my-find-file-check-make-large-file-read-only-hook () To help with large files, I've installed my own find-file-hook which turns on fundamental mode (avoids font-lock), turns off undo, and makes the buffer read-only just to avoid any accidental changes (making unnecessary backups of large files).