< * IbufferMode is ColinWalters advanced replacement for BufferMenu.
< * BufferMenuPlus -- Enhancements to the standard BufferMenu
> * BufferMenuPlus, IbufferMode -- Enhancements to the standard BufferMenu
이 페이지는 사용자들 이 쓴글과 Elisp 들을 분리해야 합니다.
지금까지 수년간 이맥스를 사용해왔지만 극한의 가능성은 언제나 도달할 수 없었습니다.
나는 이맥스를 사용하는 터무니 없이 생산적이 사람들을 보았습니다. 수시간 걸려야 완료되는 것을 수분 내에 하기 위해 키보드를 빨리 움직이는 것 처럼 보였습니다. 나는 그들이 빠르게 일을 하게 해주는 이맥스 기교를 많이 알고 있다고 결론을 내렸습니다. 그들에게 대충 물었을때 그들은 그들의 기교를 나에게 보여주는 것에 짜증을 냈습니다. (그들이 많은 시간이 빼았겼다는 점에서 이해합니다.)
그래서 나는 사람들이 이맥스를 효과적으로 사용하기 위한 자잘한 기교를 모두 설명한 웹 페이지를 만들었습니다.
멋진 기교들입니다. 어떤 것은 [[이맥스채널?]]에서 언급된 것입니다.
(add-hook 'help-mode-hook (lambda () (define-key help-mode-map "l" 'help-go-back)))
Nifty tricks for Dired are on their own page: DiredPower.
Not-A-Number is a number! How can you test for NaN? See NotANumber.
‘C-w’adds the word following point to the search buffer. Very useful.
‘C-y’adds the rest of the current line to the search buffer. Sometimes useful.
‘isearch’as a navigation mechanism. Consider modifying Isearch’s behavior by using IsearchOtherEnd.
‘enable-recursive-minibuffers’non-nil, then you can bring up a complex search and replace that you’ve just done (either because it didn’t work and you want to try again, or because you want to another similar one) in the MiniBuffer using the history mechanism, and use search and replace to edit the original search and replace. For example, if you’ve just replaced “aabbcc” with “zzbbyy” and now want to replace “aaddcc” with “zzddyy”, you can bring up the original search, and use replace-string to change the “bb” strings to “dd” in both pattern and replacement.
When replacing some text with M-% or M-C-% you may replace and edit the matches with C-w or just edit with C-r and leave recursive edit with M-C-c. This is useful when you need to replace some text, but in certain places it should differ.
A useful adjunct to keyboard macros is the ability to use multiple buffers or windows in a macro. When doing a complex keyboard macro I sometimes lose track of where the point and mark is, or maybe I need to keep track of more locations.
‘M-mouse-1’on the word, then
‘M-mouse-2’to insert. Very easy. With library second-sel.el, you can do more: swap primary and secondary, use a ring of secondary selections,…
The default emacs keybindings aren’t the most convenient for quick deletion without saving to the kill ring. a package called tinyeat in TinyTools offers a lot of useful delete functionality:
helpers for two kinds of deletion
and operations on words:
I tweaked it a bit, here are some of my helpers:
(global-set-key [(delete)] (lambda () (interactive) (re-search-forward "\\s-*" nil t) (tinyeat-delete-whole-word))) ;; only because I'm too lazy to move forward to the next word to delete. (global-set-key [(shift backspace)] (lambda () (interactive) (re-search-backward "\\s-*" nil t) (backward-char 1) (tinyeat-delete-whole-word))) ;; another lazy thing ;; I want to paste something I just saved to the kill ring without having the current region get saved. (global-set-key "M-del" 'delete-region)
Just my bindings. The tiny tools are great tho, I highly recommend them – AaronBrady
delete-trailing-whitespacein Emacs 21 and later. For those of us using earlier versions, use the PictureModeTrailingWhitespaceTrick.
(add-hook 'reftex-load-hook 'imenu-add-menubar-index) (add-hook 'reftex-mode-hook 'imenu-add-menubar-index)
(global-set-key [down-mouse-3] 'imenu)
Emacs*Xlw''''''Menu*fontSet: -*-helvetica-medium-r-normal-*-*-120-*-*-*-*-*-* Emacs*Xlw''''''Menu*foreground: black Emacs*Xlw''''''Menu*shadowThickness: 1
run-with-idle-timerhas a million and one uses. The following use has vastly improved my life using NTEmacsWithCygwin, for example. Here’s the problem it solves: I frequently want to switch to a buffer named “Shell”; I’ve formed the habit of typing merely
* S h e RET, and letting completion complete the buffer name. However, sometimes there’s a buffer lying around named “Shell Command Output”. Since that buffer’s name shares a common prefix with the name of the buffer to which I want to switch, completion doesn’t completely complete the name “Shell”; instead it leaves me with “*Shell”. Thus, when I then hit RET, I find myself looking at a new, empty, useless buffer instead of the one I wanted. Rather than telling completion to honor case (which is annoying on Win32, since the file system is itself case-insensitive), I simply tell Emacs to periodically kill any buffers named “Shell Command Output” that it finds lying around (if they’re not currently displayed in a window). The “periodically” part is what run-with-idle-timer does for us.
(if completion-ignore-case (defvar reaper (run-with-idle-timer 5 t (lambda () (let ((victim (get-buffer "*Shell Command Output*"))) (when (and victim (not (get-buffer-window victim t))) (message "Killing buffer %s" (buffer-name victim)) (kill-buffer victim))))) "idle-timer (see \\[run-with-idle-timer]) that deletes the *Shell Command Output* buffer -- that buffer's name is so similar to *shell* that completion makes the latter hard to type. Use \\[cancel-timer] to cancel it."))
(setq hcz-set-cursor-color-color "") (setq hcz-set-cursor-color-buffer "") (defun hcz-set-cursor-color-according-to-mode () "change cursor color according to some minor modes." ;; set-cursor-color is somewhat costly, so we only call it when needed: (let ((color (if buffer-read-only "black" (if overwrite-mode "red" "blue")))) (unless (and (string= color hcz-set-cursor-color-color) (string= (buffer-name) hcz-set-cursor-color-buffer)) (set-cursor-color (setq hcz-set-cursor-color-color color)) (setq hcz-set-cursor-color-buffer (buffer-name))))) (add-hook 'post-command-hook 'hcz-set-cursor-color-according-to-mode)
‘find-file’, completion+cycling interface to your recent files.
(set-register ?e '(file . "~/.emacs")) (set-register ?i '(file . "~/org/ideas.org"))
Then use C-x r j e to open the .emacs file, and C-x r j i for the ‘ideas’ file. For C-x r j, think ‘register jump’.
‘ffap-alist’to tell Emacs where to find them. -PiotrMieszkowski
*SelectiveDisplay? - a poor-man’s OutlineMode. It hides lines with less then the provided number of spaces in front. It can help in getting a quick overview of files as long as paragraph lines are further indented than headlines. This is great for viewing man pages: C-u 1 M-x set-selective-display to show only headings, M-x <up> RET to disable it again.
*CategorizingInformationManager by JuriLinkov is a great way to categorize views in Emacs. It lets you see lists of buffers, or processes, or info docs, or files, and so on. You can switch between views specific to the type of data you are looking at. For example, M-x ee-buffers brings up a list of buffers. You can jump between views by encoding, dired-style, by directory, by project, etc. It’s awesome!
(eval-after-load "dabbrev" '(defalias 'dabbrev-expand 'hippie-expand))
(global-set-key [(shift end)] '(lambda () (interactive) (other-window -1)))
(defun indent-or-complete () "Complete if point is at end of a word, otherwise indent line." (interactive) (if (looking-at "\\>") (dabbrev-expand nil) (indent-for-tab-command) ))
(add-hook 'c-mode-common-hook (function (lambda () (local-set-key (kbd "<tab>") 'indent-or-complete) )))
(add-hook 'find-file-hooks (function (lambda () (local-set-key (kbd "<tab>") 'indent-or-complete))))
(defun indent-or-complete () "Complete if point is at end of line, and indent line." (interactive) (if (looking-at "$") (hippie-expand nil)) (indent-for-tab-command))
(defun indent-or-complete () "Complete if point is at end of line, and indent line." (interactive) (if (and (looking-at "$") (not (looking-back "^\\s-*"))) (hippie-expand nil)) (indent-for-tab-command) )
(setq mail-user-agent 'message-user-agent)
(setq mail-user-agent 'gnus-user-agent)
(defun search-google () "Prompt for a query in the minibuffer, launch the web browser and query google." (interactive) (let ((search (read-from-minibuffer "Google Search: "))) (browse-url (concat "http://www.google.com/search?q=" search))))
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate) “I feel very ANNOYING of \“Active processes exist\” query when exiting.” (flet ((process-list ())) ad-do-it))
I bet this is a FAQ. – rubikitch
Bind your F1…F12 keys to do useful things.
I bind F12 to compile, it makes a nifty mini-shell for running various utilities. Especially grep like things.
Make sure you have a proper psgml and the proper DTD’s when writing html. In fact don’t write html any more. Write XHTML. Then emacs+psgml+DTD makes you very productive.
Learn gdb under the GUD.
#!/bin/sh u=$2 shift shift sudo -u $u gdb -fullname $*
Learn the version control stuff.
Anyone not knowing how to use query-replace-regexp has not and cannot become emacs enlightened.
Use M-| to feed bits of text to perl/ruby one-liners or scripts. M-1 M-| to replace the text.
M-x sort-lines can be useful.
I use TAGS quite a lot.
I bind M-g to goto-line
The writing on the left ctrl key of my keyboards wears off first…
;; move current function up (defun my-move-function-up () (interactive) (save-excursion (c-mark-function) (kill-region (region-beginning) (region-end)) (c-beginning-of-defun 1) (yank))) ;; move current function down (defun my-move-function-down () (interactive) (save-excursion (c-mark-function) (kill-region (region-beginning) (region-end)) (c-beginning-of-defun -1) (yank)))
Your comments are welcome.
Probably you you can use
‘delete-and-extract-region’ instead of
I too use M-x sort-lines, often followed by M-x uniqify-buffer (which I wrote myself) – it removes all but one line in every sequence of repeated lines in the buffer.
You could get the same effect with C-x h M-| uniq RET, but not all systems have
‘uniq’, and this function might be faster.
Take advantage of escreen. It is really handy for when you have your buffers all lined up the way you want, but need to either temporarily switch tasks or temporarily open a new buffer. Escreen gives you a “whole new frame”; it doesn’t mess with anything in the other “frame”. The advantage over C-x 5 2 is that it also doesn’t screw up your window layout on your desktop.
Read EmacsNiftyTricks and drop by the #emacs channel on irc.openprojects.net and chat with the gurus.
Poor man’s tagging: find all the files in the “project” and use M-/ – this works because Emacs searches through all the buffers for the completion. --ttn
My project uses LXR and runs cron jobs every night to tag the entire code base. I wrote:
So I have better TAGS than TAGS, symbol completion in C/C++/Java mode and a faster grep than grep. I could have used the mysql client directly but the LXR database doesn’t accept remote clients (for security reasons.)
A lot of times, programming effectively with Emacs would take a bit of elisp hacking. – LinhDang
C-u M-! command will insert the result of running command in the current buffer. I didn’t know that, and wrote a small function to do that. Very handy for things like date. – AadityaSood
Enhance your movements
C-x r i, you may use a prefix argument to jump to the end of the inserted text, but if you forget you can use
C-a TABto jump to identation point.
‘reindent-then-newline-and-indent’command. For example if you have long line and you want move part of it to new line, just move point to the place where splist must be done and do
M-x reindent-then-newline-and-indent RET
C-x C-n (`set-goal-column')when doing vertical editing.
list-matching-lines and desktop.el and bs.el
(ok 3 words).
Does anyone else here find themselves trying to edit these pages with C-n,C-p, etc….?
Some of my handiest bindings are:
C-’ to do ‘other-window (i’m a big split window fan)
C-ca to do ‘list-matching-lines. Show all occurrences of a regex in another window, and jump around in the buffer by selecting them.
I could go on. (and on and on and on)
Try desktop.el truly. It allows for multiple named “desktops” that you can switch in/out of really easy.
Oh, yeah - almost forgot….. sql-oracle rocks-my-world
enuff for now. Anyone with me? --DC
(defun filter (fn lst) (let ((acc nil)) (dolist (x lst) (let ((val (funcall fn x))) (if val (push val acc)))) (nreverse acc))) (defun setOverlayBookmark () (interactive) (let* ((pnt (line-beginning-position)) (ovrly (make-overlay pnt (line-end-position)))) (overlay-put ovrly 'face 'highlight) (overlay-put ovrly 'pointHistory t) ovrly)) (defun overlayBookmarkFilterFunc (ovrly) (and (overlay-get ovrly 'pointHistory) ovrly)) (defun overlayBookmarkFilterStartsFunc (ovrly) (and (overlay-get ovrly 'pointHistory) (overlay-start ovrly))) (defun nextOverlayBookmark () (interactive) (let* ( (pnt (line-end-position)) (ovrly_starts (or (filter 'overlayBookmarkFilterStartsFunc (overlays-in pnt (point-max))) (filter 'overlayBookmarkFilterStartsFunc (overlays-in (point-min) pnt))))) (if ovrly_starts (goto-char (reduce (lambda (a b) (if (< a b) a b)) ovrly_starts)) (message "no items in history")))) (defun clearOverlayBookmarks () (interactive) (let ((ovrlys (filter 'overlayBookmarkFilterFunc (overlays-in (point-min) (point-max))))) (mapcar 'delete-overlay ovrlys) (message "cleared point history"))) (defun toggleOverlayBookmark () (interactive) (let ((ovrlys (filter 'overlayBookmarkFilterFunc (overlays-in (line-beginning-position) (line-end-position))))) (if ovrlys (mapcar 'delete-overlay ovrlys) (setOverlayBookmark)))) (defun overlayBookmarkRefresh () "stretches the overlays from the beginning to end of a line" (interactive) (let ((ovrlys (filter 'overlayBookmarkFilterFunc (overlays-in (point-min) (point-max)))) (lf (lambda (tmp) (save-excursion (goto-char (overlay-start tmp)) (move-overlay tmp (overlay-start tmp) (line-end-position))))) ) (if ovrlys (mapcar lf ovrlys) (setPointHistory))))
I happen to bind it like this:
(global-set-key [C-f12] 'clearOverlayBookmarks) (global-set-key [f12] 'nextOverlayBookmark) (global-set-key [M-f12] 'toggleOverlayBookmark)
and f12 takes you to the next bookmark. Nothing too fancy, let me know if its useful to anyone.
The real advantage of this system is that if you save point markers they’ll inevitably move to the wrong position at some point, but emacs does a great job of keeping overlays with the text that they affect, so you can delete or insert hundreds of lines above the bookmarks and the markers will still be accurate (unlike saved point markers)
Be default it highlights the marked line. ‘underline also works if this is too invasive (just change ‘highlight to ‘underline in the set function). I thought about putting something in the margin, but the elisp docs weren’t too clear (you can embed an image, but not sure about color or shapes), so if someone adds this let me know.
See also Wiki:GreatEmacsFeatures.