- Main Hotkeys
- Basic Navigation
- Advanced Navigation
- Buffer Management
- Region Management
- Classes
- Compilation
- Comments
- Bookmarks
- Shell
- Copying and Pasting
- Function Without Keybindings
- Getting Help
- Extended Functionality
- Changing and Saving Settings
- Mark Ring
- Kill Ring
Our Emacs install has been heavily customized to work seamlessly with CM. We have our own functions and commands that help developers write code in CM in an efficient manner.
Here's a collection of some of the more useful commands we have in Emacs :
Main Hotkeys
- M: Alt
- C: Ctrl
- S: Shift
- H: Windows
Basic Navigation
- C-f: Move one character forward
- C-b: Move one character backward.
- C-n: Move to the next line.
- C-p: Move to the previous line.
- M-f: Move one word forward.
- M-b: Move one word backward.
- C-a: Move to the start of the line.
- C-e: Move to the end of the line.
- M-m: Move to the start of the indentation (on the current line).
Advanced Navigation
- M-S-]: Jump to the beginning of the next block of white spaces.
- M-S-[: Jump to the beginning of the previous block of white spaces.
- M-i: Jump to definition of thing at point.
- C-M-i: Return to where M-i was called.
- C-M-(: Go to the parent, bracket, or brace matching character at point.
- H-n: Jump to next definition in file.
- H-p: Jump to previous definition in file.
- C-v: Scroll the display one screen forward.
- M-v: Scroll the display one screen backward.
- C-l: Make the current line the center-most text line in the selected window.
- M-g: Goto line.
- C-M-g: Goto char (position in file, useful for external stack dumps lacking line numbers)
Buffer Management
- C-x n n: Hide everything apart from the content that is in the highlighted region. (Focus Mode)
- C-x n d: Narrow down to the current function.
- C-x n w: Widen to make the entire buffer accessible again.
Region Management
- M-%: Allows you to replace text within the selected region.
- C-/: Undo changes within the selected region.
- C-M-\: Indents the selected region.
Classes
- C-c C-o: Jump to the super() method overridden by method at point, if any.
- C-c C-i: Display all methods implementing method at point, if any.
- C-c C-s: Display all subclasses of class if point inside the class body.
- C-c C-n: Jump to the next class declaration in current buffer.
- C-c C-q: Display all fields in the hierarchy of the class at point.
- C-c C-a: Display all methods in the hierarchy of the class at point.
- C-c C-w: Bring up the class viewer dialog.
- You can control what you see in the dialog (fields, methods, constructors) by changing the arguments in the showClassViewer call within the showClassViewerDummy function in cm.runtime.console.classViewer.cm.
Compilation
- M-p: Run boot file.
- C-c C-e: Run boot file as release mode.
- C-M-u: Reloading the current package.
- C-M-y: Reloading all known packages.
Comments
- C-M-k: Inserts comment box in file.
- C-M-j: Inserts divider comment box in file.
- C-]: Comment out current line.
- H-]: Comment out current line and paste it on next line.
- C-M-c: Cut out marked region.
- H-c: Delete CUT_THIS_OUT if point inside CUT_THIS_OUT block.
Bookmarks
- C-F1 through C-F12 bookmarks a spot, and the selected Fn key from F1 through F12 (without Ctrl) will jump to the bookmarked spot.
Shell
It is possible to run shell commands directly from Emacs by using one of the following commands:
- M-! (or M-x shell-command): Allows you to execute a single shell command.
- M-x shell: Brings up a shell, allowing you to run as many shell commands as you want!
Copying and Pasting
- M-x delete-selection-mode: Enabling delete-selection allows you to overwrite the highlighted text when pasting.
- M-y: Pressing M-y immediately after C-y (pasting) replaces the yanked text with the text preceding it in the kill ring.
- C-M-w: Copies code, and preserves the formatting. You might want to use this for your emails!
Function Without Keybindings
These are some functions that do not (yet) have any keybindings defined (but can be run from the M-x menu):
- cm-toggle-fold: Toggle hiding everything inside function definitions (just show the function comments, arguments, etc.). Handy for skimming through a big file.
- cm-insert-class-template: Insert a cm class template.
- cm-revert-all-cm-buffers: This refreshes any buffers that have been externally modified (e.g. when update fetches changes from git), so the buffer message "someFile.cm changed on disk; really edit the buffer? (y, n, r or C-h)" doesn't interrupt your zen.
- cm-insert-getter-and-setter: If you set a variable definition of the form "private varType _varName", it generates interface functions to access or modify the variable. For example: "private Wookiee _chewbacca;" gets
extend public Wookiee chewbacca=(Wookiee n) { return _chewbacca = n; } extend public Wookiee chewbacca() { return _chewbacca; }
If you type C-u before running cm-insert-getter-and-setter, it will instead insert
extend public Wookiee chewbacca=(Wookiee n) { return _lastChewbacca = _chewbacca = n; }
which will cache the value in _lastChewbacca, provided the variable is already defined.
(If you don't have some of these, your Emacs process was started before they were defined.)
Getting Help
- C-h i: the info directory, a lot of information about Emacs.
- C-h k: describe a key binding in Emacs.
- C-h f: describe function.
- C-h v: describe variable.
Extended Functionality
You can run on ido-mode by adding (cm-ido-init) to your .emacs or in your emacs/user/unsername.el if you have one. Ido mode is an alternate completing mechanism that overrides the behavior of find-file and some other similar functions. It allows for much better searching (it finds filenames containing the search string, as opposed to the std behavior that only finds filenames beginning with it), but it takes a while to get used to it. Useful keys in ido mode:
- C-s: go to next match in the ido-list
- C-f: revert back to the std find-file behavior
If you have ido-mode in your M-x buffer, you can run SMEX(Smart M-x). To get SMEX, follow these steps:
- Download smex.el from https://github.com/nonsequitur/smex/ and save somewhere on your computer, for example in ~/.emacs.d/plugins/smex/smex.el
- Load the path to the location of your smex.el in your Emacs file:
(add-to-list 'load-path "~/.emacs.d/plugins/")
- Load and initialize SMEX:
(load "smex/smex.el") (require 'smex) (smex-initialize)
- In your .emacs, rebind M-x to run SMEX:
(global-set-key (kbd "M-x") 'smex)
Changing and Saving Settings
You can set and save Emacs variables by using the commands below:
- M-x customize-set-variable: Sets the value of an Emacs variable.
- M-x customize-save-variable: Sets and saves an Emacs variable across future sessions.
You will need to type the name of the variable you want to set/save afterwards. Pressing TAB will show you the available variables you can set.
For example, if you want the 'Ignore Case for Search' option in the options toolbar to be enabled by default, you can use M-x customize-save-variable followed by case-fold-search, then hitting y.
Mark Ring
When you place a mark (with C-Space, or clicking and dragging to highlight an area), the position marked is added to the mark ring. You can jump back to previous mark locations by pressing C-u C-Space ("giving it a prefix argument"). Typing C-u C-Space again will move back one more point in the mark-ring each time.
Some commands that move a long way, like beginning-of-buffer or isearch-forward, will also add the current location to the mark ring before moving. Consequently, this can be used as a "move back to where I was before I did that" command.
You can also pop one mark back in the global mark ring (that is, jumping to previous buffers as well) by typing C-x C-Space.
Kill Ring
After pressing C-y to yank (aka paste) text, you can press M-y repeatedly to replace what you just yanked with successively earlier stuff. This is called the kill-ring; when you stuff goes in there, instead of replacing the old value, it just pushes it back further in the list. Some other commands besides cutting/copying with C-w or M-w also add to the kill-ring (i.e. deleting lines with C-k), so you might find what you wanted to insert has been unexpectedly replaced. It's still available.
Comments
0 comments
Please sign in to leave a comment.