1title:: Emacs Editor 2categories:: Frontends 3summary:: Using SuperCollider in Emacs 4 5section:: Keyboard shortcuts 6Here is a more extensive and elaborate overview of useful shortcuts in the Emacs Editor. For a general reference to Emacs shortcut, check out this link::http://lpn.rnbhq.org/tools/xemacs/emacs_ref.html##Emacs reference::. 7definitionlist:: 8## C-g || Abort current action 9## C-h || General help on emacs 10:: 11subsection:: Interpreting code 12definitionlist:: 13## C-c C-d 14(C-c C-c) || Interpret Selection 15(only if transient-mark-mode is on) 16## C-c C-c || Interpret current line 17## C-c C-e || Evaluate expression (in minibuffer) 18## C-M-x || Interpret defun 19## C-c C-f || Interpret current document 20:: 21subsection:: Control the interpreter 22definitionlist:: 23## C-c C-s || Stop (CmdPeriod) / Main.stop 24## C-c C-r || Main.run 25## C-c C-l || Recompile library 26## M-x sclang-stop || Stop interpreter 27## C-c C-p p || Show server panels 28:: 29subsection:: Postbuffer and workspace 30definitionlist:: 31## C-c C-w || Switch to workspace 32## C-c < || Clear postbuffer 33## C-c > || Show postbuffer 34:: 35subsection:: Help files 36definitionlist:: 37## C-M-h || Show help browser 38## C-c C-h || Open help file. You do not need to select a word before using the shortcut. It will suggest the word at the current cursor position, or lets you type a word in the minibuffer. There is autocompletion by typing <TAB>. 39## E (in the help browser) || open the help file as plain text (in sclang-mode), so it can be edited. 40## C-c C-v (in the help browser) || edit the help file as html code. 41:: 42subsection:: Finding things in class source files 43definitionlist:: 44## C-c : || Find definitions (method or class). Again, you can type the word you want to look for in the minibuffer and it suggests the word at the current cursor position. 45## C-c ; || Find references to (method or class). (ditto) 46## C-c C-k || Open current file at the svn development path location. You need to have set the devpath variable in Platform for this to work properly, e.g. 47thisProcess.platform.devpath = "~/svn/SuperCollider3".standardizePath; 48:: 49subsection:: Current code completion and interface 50definitionlist:: 51## C-c [ || Dump interface 52## C-c { || Dump full interface 53## C-c C-m / C-c RET || Show method arguments (in minibuffer) 54## C-c C-n / M-TAB || Autocomplete keyword (either puts in the one possible completion, or pops up a buffer with possibilities from which you can choose one) 55:: 56subsection:: Files and buffers 57definitionlist:: 58## C-x C-f || Open file or new file 59## C-x C-s || Save file 60## C-x C-w || Save file as 61## C-x C-v || Open another file in this buffer 62## C-x i || Insert a file at cursor position 63## C-x b || Create/switch buffers 64## C-x C-b || Show buffer list 65## C-x k || Kill buffer 66## C-z || Suspend emacs 67## C-x C-c || Close down emacs 68:: 69subsection:: Undo and recovery 70definitionlist:: 71## C-x u / C-_ || Undo 72## C-x u / C-_ || Redo 73## M-x revert-buffer RETURN || undo all changes since last save 74## M-x recover-file RETURN || Recover text from an autosave-file 75## M-x recover-session RETURN || Recover text from an autosave-files if you edited several files 76:: 77subsection:: Editing 78definitionlist:: 79## M-w || Copy 80## C-y || Paste 81## C-w || Cut 82## C-x C-o || Delete blank lines 83:: 84subsection:: Search and replace 85definitionlist:: 86## C-s || Search / find. This allows you to set a string in the mini-buffer. The occurrences in the text will be highlighted and you can press C-s again and again to jump to next occurrences 87## C-r || Search / find backwards. 88## M-% || Replace and find next 89## M-, || Replace 90:: 91subsection:: Navigating and selecting 92definitionlist:: 93## M-g g || Goto line ... 94## C-x a || Select all 95## C-M-f || zips you forward to matching parenthesis, so if you hover over the opening bracket, hit 96C-<space>, C-M-f, C-c C-c you can quickly execute a block. 97## C-M-b || zips you backward to matching parenthesis. If you are just to the right of closing brackets this is handier if you've just finished some code. 98## C-f || Move forward a character 99## C-b || Move backward a character 100## M-f || Move forward a word 101## M-b || Move backward a word 102## C-n || Move to next line 103## C-p || Move to previous line 104## C-a || Move to beginning of line 105## C-e || Move to end of line 106## M-a || Move back to beginning of sentence 107## M-e || Move forward to end of sentence 108:: 109subsection:: Formatting 110definitionlist:: 111## M-x show-paren-mode || Paren match highlighting. Can also be set from the options menu. 112## M-; || Add comment. If you have a text selected, then that text will become a comment. It will remove the commenting // when you have selected a commented text. 113## C-M-j || Continue the comment on the next line. 114## C-u M-; || Remove comment. This removes the whole comment, so also the text! 115## M-x comment-region || Comments the selected region 116## M-x uncomment-region || Uncomments the selected region 117## TAB || Auto-aligns tabs according to code. 118:: 119 120section:: Marks 121(info from EmacsWiki) 122subsection:: set-mark-command (`C-SPC') 123A nice feature that not all know about is what happens if you feed it with a universal argument: ‘C-u C-SPC’. It’s an easy way to navigate back to your previous editing spots by jumping to the positions stored in the buffer’s local mark ring. Repeated calls will cycle through the ring of marks. 124 125If you use TransientMarkMode and you want to set the mark but don’t want to subsequently see the region highlighting, you can use ‘C-SPC C-g’ to set the mark and then deactivate it. 126 127subsection:: pop-global-mark (`C-x C-SPC') 128In addition to the ordinary mark ring that belongs to each buffer, Emacs has a single global mark ring. It records a sequence of buffers in which you have recently set the mark, so you can go back to those buffers. 129 130Setting the mark always makes an entry on the current buffer’s mark ring. If you have switched buffers since the previous mark setting, the new mark position makes an entry on the global mark ring also. The result is that the global mark ring records a sequence of buffers that you have been in, and, for each buffer, a place where you set the mark. 131 132‘C-x C-SPC’ (‘pop-global-mark’) jumps to the buffer and position of the latest entry in the global mark ring. It also rotates the ring, so that successive uses of ‘C-x C-SPC’ take you to earlier and earlier buffers. 133 134section:: Customizing Emacs' behavior 135 136You can customize the behaviour of Emacs, by putting things in the startup file of emacs. This file is code:: ~/.emacs ::. You can define options there, for example: 137code:: 138(custom-set-variables 139 '(case-fold-search t) 140 '(global-font-lock-mode t nil (font-lock)) 141 '(sclang-runtime-directory "~/SuperCollider/") 142 '(show-paren-mode t nil (paren)) 143 '(transient-mark-mode t) 144) 145:: 146nil means that an option is turned off, t or 1 means that it is turned on. 147code:: 148'(sclang-eval-line-forward nil) 149:: 150Configure the text cursor NOT to move after hitting C-c C-c 151 152subsection:: Customize w3m 153 154Normally w3m uses the arrow keys to jump between hyperlinks. For browsing SC help files this is not very useful. 155code:: 156(eval-after-load "w3m" 157 '(progn 158 (define-key w3m-mode-map [left] 'backward-char) 159 (define-key w3m-mode-map [right] 'forward-char) 160 (define-key w3m-mode-map [up] 'previous-line) 161 (define-key w3m-mode-map [down] 'next-line) 162 (setq w3m-auto-show 1) 163 )) 164:: 165 166subsection:: Automatically complete brackets and parentheses 167code:: 168 (setq skeleton-pair t) 169 (global-set-key (kbd "(") 'skeleton-pair-insert-maybe) 170 (global-set-key (kbd "{") 'skeleton-pair-insert-maybe) 171 (global-set-key (kbd "[") 'skeleton-pair-insert-maybe) 172 (global-set-key (kbd "\"") 'skeleton-pair-insert-maybe) 173 (global-set-key (kbd "'") 'skeleton-pair-insert-maybe) 174:: 175 176subsection:: Scrollwheel support 177code:: 178;;; scrollwheel support 179(defun scroll-up-half () 180 "Scroll up half a page." 181 (interactive) 182 (scroll-up (/ (window-height) 2)) 183 ) 184 185(defun scroll-down-half () 186 "Scroll down half a page." 187 (interactive) 188 (scroll-down (/ (window-height) 2)) 189 ) 190(global-set-key [(mouse-5)] 'scroll-up-half) 191(global-set-key [(mouse-4)] 'scroll-down-half) 192:: 193 194subsection:: Recent files menu 195 196Recentf is a minor mode that builds a list of recently opened files. This list is automatically saved across Emacs sessions. You can then access this list through a menu. Put this in your `~/.emacs’: 197code:: 198(require 'recentf) 199(recentf-mode 1) 200:: 201For adding a shortcut (C-x C-r) to open a recent file add this code as well: 202code:: 203(defun recentf-open-files-compl () 204 (interactive) 205 (let* ((all-files recentf-list) 206 (tocpl (mapcar (function 207 (lambda (x) (cons (file-name-nondirectory x) x))) all-files)) 208 (prompt (append '("File name: ") tocpl)) 209 (fname (completing-read (car prompt) (cdr prompt) nil nil))) 210 (find-file (cdr (assoc-ignore-representation fname tocpl))))) 211 212(global-set-key "\C-x\C-r" 'recentf-open-files-compl) 213:: 214 215section:: More info on Emacs 216 217See the link::http://www.emacswiki.org/cgi-bin/wiki##Emacs Wiki:: 218