This document reveals some tips and tricks about various defaults you can use to customize the behavior of Cocoa’s text system. It also describes how to customize the key bindings supported by the text system.
Feb 18, 2007 Emacs Key Bindings in MS Word February 18th, 2007 by Ryan McGeary 189 Comments. Tags: misc osx search thesis windows. 189 responses so far ↓. The first one adds Option-key bindings for some common Emacs behavior. This might be useful where the Option key bindings are not standard. With these bindings it would be necessary to type “ Control-Q, Option-f ” in order to type a florin character instead of moving forward a word. When using the vanilla EmacsforOsx binary, a useful site for setting, at least, Emacs server and Emacs client applications is Configuring Emacs on Mac OS X. Emacs shell environments behave differently from Terminal environments and in order to have correct environments like LANG=enGB.utf-8 LCALL=enGB.utf-8 or PATH= for sub-applications.
Heavy-duty subclassers may alter some or all of the text system's functionality, rendering some or all of these features inactive.
Key Bindings
The text system uses a generalized key-binding mechanism that is completely re-mappable by the user, although defining custom key bindings dynamically (that is, while the application is running) is not supported. Key bindings are specified in an dictionary file that must have an extension of
.dict
; the format of this file should be an XML property list, but the text system can also understand old-style (NeXT era) property lists. The standard key bindings are specified in /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict
. These standard bindings include a large number of Emacs-compatible control key bindings, all the various arrow key bindings, bindings for making field editors and some keyboard UI work, and backstop bindings for many function keys.To customize bindings, you create a file named
DefaultKeyBinding.dict
in ~/Library/KeyBindings/
and specify bindings to augment or replace the standard bindings. You may use the standard bindings file as a template. It is recommended that you use the Property List Editor application to edit a bindings dictionary. You may use another application such as TextEdit or Xcode, but if you do you must ensure the encoding of the saved file is UTF8.Key bindings are key-value pairs with the key being a string that specifies a physical key and the value identifying an action method to be invoked when the key is pressed. (Many of these action methods are declared by
NSResponder
.) You can compose physical-key strings using the following elements: - The alphanumeric character that appears on a US keyboard. For example, 'f' or '>'. (As noted below, some special characters are reserved for modifier flags.)
- For a few keys, such as Escape, Tab, and backward Delete (BS), the octal number from the ASCII table that identifies the key. For example, the octal number identifying the Escape key (sometimes used as a modifier key) is
033
. - An
enum
constant assigned a unique Unicode value that is used to identify a function key. These constants are defined inNSEvent.h
. Examples of these constants areNSF7FunctionKey
,NSHomeFunctionKey
, andNSHelpFunctionKey
. - Intel desktop board dh61cr manual. One or more key modifiers, which must precede one of the other key-identifier elements. The following special characters are used for modifier flags:
- “
^
” for Control - “
~
” for Option - “
$
” for Shift - Ati radeon hd 2600 pro agp rv630 drivers for mac. “
#
” for numeric keypad
For example, the following string would identify the 0 (zero) key on the numeric keypad when the Control key is pressed simultaneously: '^#0
'.
The text system supports the specification of multiple keystroke bindings through nested binding dictionaries. For instance, Escape could be bound to
cancel:
Imovie 9 download mac. or it could be bound to a whole dictionary which would then contain bindings for the next keystroke after Escape.The following sample binding files illustrate how you might customize bindings. The first one adds Option-key bindings for some common Emacs behavior. This might be useful where the Option key bindings are not standard. With these bindings it would be necessary to type “
Control-Q, Option-f
” in order to type a florin character instead of moving forward a word. This sample also explicitly binds Escape to complete:
. (In OS X, this is the default so this override changes nothing.)The following example shows how to have multi-keystroke bindings. It binds a number of Emacs meta bindings using Escape as the meta key instead of the Option modifier. So Escape followed by the 'f' key means
moveWordForward:
here. This sample binds Escape-Escape to complete:
. Note the nested dictionariesOnce you have completed specifying key bindings, you must save the file and relaunch the application for the bindings to take effect. With the right combination of key bindings and default settings, it should be possible to tailor the text system to your preferences.
Standard Action Methods for Selecting and Editing
The
NSResponder
class declares method prototypes for a number of standard action methods, nearly all related to manipulating selections and editing text. These methods are typically invoked through doCommandBySelector:
as a result of interpretation by the input manager. They fall into the following general groups:- Selection movement and expansion
- Text insertion
- General deletion of elements
- Modifying selected text
- Scrolling a document
In most cases the intent of the action method is clear from its name. The individual method descriptions in this specification also provide detailed information about what such a method should normally do. However, a few general concepts apply to many of these methods, and are explained here.
Selection Direction
Some methods refer to spatial directions; left, right, up, down. These are meant to be taken literally, especially in text. To accommodate writing systems with directionality different from Latin script, the terms forward, beginning, backward, and end are used.
Selection and insertion point
Methods that refer to moving, deleting, or inserting imply that some elements in the responder are selected, or that there’s a zero-length selection at some location (the insertion point). These two things must always be treated consistently. For example, the
insertText:
method is defined as replacing the selection with the text provided. The moveForwardAndModifySelection:
method extends or contracts a selection, even if the selection is merely an insertion point. When a selection is modified for the first time, it must always be extended. So a moveForward.
message extends the selection from its end, while a moveBackward.
message extends it from its beginning.Marks
A number of action methods for editing text imitate the Emacs concepts of point (the insertion point), and mark (an anchor for larger operations normally handled by selections in graphical interfaces). The
setMark:
method establishes the mark at the current selection, which then remains in effect until the mark is changed again. The selectToMark:
method extends the selection to include the mark and all characters between the selection and the mark.The kill buffer
Also like Emacs, deletion methods affecting lines, paragraphs, and the mark implicitly place the deleted text into a buffer, separate from the pasteboard, from which you can later retrieve it. Methods such as
deleteToBeginningOfLine:
add text to this buffer, and yank:
replaces the selection with the item in the kill buffer.Text System Defaults
![Emacs Bindings For Word For Mac Emacs Bindings For Word For Mac](https://macin.files.wordpress.com/2008/10/aquamacs-screenshot.png)
NSMnemonicsWorkInText
Allowed value: 'YES' or 'NO'.
This default controls whether the text system accepts key events with the Option key down. The default value is
NO
. A value of YES
means that any key event with the Option bit on will be passed up the responder chain to eventually be treated as a mnemonic instead of being accepted by the text as textual input or a key binding command. If this default is set to NO then the key events with the Option bit set will be passed through the text system's normal key input sequence. This will allow any key bindings involving Option to work (such as Emacs-style bindings like Option-f for word forward) and it allows typing of special international and Symbol font characters.NSRepeatCountBinding
Allowed value: Key-binding style string.
This default controls the numeric argument binding. The default is for numeric arguments not to be supported. If you provide a binding for this default you enable the feature. This allows you to repeat a keyboard command a given number of times. For instance “
Control-U 10 Control-F
” means move forward ten characters.NSQuotedKeystrokeBinding
Allowed value: Key-binding style string.
This default controls the quote binding. The default is for this to be “^q” (that's Control-Q). This is the binding that allows you to literally enter characters that would otherwise be interpreted as commands. For instance “
Control-Q Control-F
” would insert a Control-F character into the document instead of performing the command moveForward:
.NSTextShowsInvisibleCharacters
Allowed value: 'YES' or 'NO'.
The default controls whether a text object will by default show invisible characters like tab, space, and carriage return using some visible glyph. By default it is
NO
. It only controls the default setting for NSLayoutManager
objects (which can be modified programmatically). In order for this to work, the rule book generating the glyphs must support the feature. Currently our rule books do not support this feature, so currently this default is not very useful.NSTextShowsControlCharacters
Allowed value: 'YES' or 'NO'.
The default controls whether a text object will by default show control characters visibly (usually by representing Control-C as “^C” in the text). By default it is
NO
. It only controls the default setting for NSLayoutManager
objects (which can be modified programmatically). In order for this to work, the rule book(s) generating the glyphs must support the feature. This feature carries a cost. It will increase the memory needed for documents that contain control characters by quite a lot. Use it with care.NSTextSelectionColor
Allowed value: Color object or specifier.
Mac Emacs 27
This default controls the background color of selected text. By default this is light gray. Defaults that accept colors accept them in one of three ways. Either as an archived
NSColor
object, or as three RGB components, or as a string that can be resolved to a factory selector on NSColor
that will return the desired color (for example, “redColor”). Note that NSTextField objects and other controls that use field editors to edit their text control their own selection attributes to conform with the UI.NSMarkedTextAttribute and NSMarkedTextColor
Allowed value: Color object/specifier or 'underline'.
This default controls the way that marked text is displayed. The
NSMarkedTextAttribute
can be either “Background
” or “Underline
”. If it is “Background
” then NSMarkedTextColor
indicates the background color to use for marked text. If NSMarkedTextAttribute
is “Underline
”, NSMarkedTextColor
indicates the foreground color to use for marked text (the marked text will be drawn in the indicated color and underlined). By default, marked text is drawn with a yellowish background color. Kit defaults that accept colors accept them in one of three ways. Either as an archived NSColor
object, or as three RGB components, or as a string that can be resolved to a factory selector on NSColor
that will return the desired color (for example, “redColor”). If the NSMarkedTextAttribute
default contains a color instead of one of the strings “Background
” or “Underline
” then that color is used as the background color for marked text and the NSMarkedTextColor
attribute is ignored.NSTextKillRingSize
Allowed value: Number string.
This default controls the size of the kill ring (as in Emacs Control-Y). The default value is 1 (not really a ring at all, just a single buffer). If you set this to a value larger than one, you also need to rebind Control-Y to
yankAndSelect:
instead of yank:
for things to work properly (note that yankAndSelect:
is not listed in any headers). See Key Bindings for more information about bindings. Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13
I came late into this game. I didn’t write python scripts when I was in kindergarten. I didn’t hack into my high school’s camera security system. My aim in this post is to show you that you equally don’t need to be a master hacker or whiz coder to get closer to your writing machine. This isn’t a how-to.
It merely points to the free software and packages you can get to start compiling text into amazing, quality files, into whichever format you want. But to get there keep in mind:
- Be patient. This can be a transformative experience if you let it happen.
- You’ll have a lot of looking-up online to do, especially if you’re just starting out. Issues will come up. Yet there are wonderful, dedicated groups of people helping out each other online. So far I haven’t had a problem for which there wasn’t at least a hint of a solution proposed.
My main impulses to do this came from
- Frustration with Microsoft Word, Scrivener and Adobe InDesign for Mac
- Will to productive procrastination.
I liked writing in Scrivener. I followed the tutorial to the “t” with the trial version, then bought my license a couple years ago and never looked back to Microsoft Word. But annoyance still crept up when I exported my dissertation files to a Word document my supervisor could read. Footnote alignment was this bottom of a page hell place. Bibliography management with Zotero was so-so. And images. Don’t even get me started on laying out photos on either Scrivener or Word.
My frustration grew to the point I’m now convinced it must be the mother of all invention — or, to make that statement a little less grandiose: of most free software. That’s also when a genial flash of imperative came in the mental thought form “you must learn Emacs and LaTeX”.
Why Emacs?
Emacs is one of the most stable, extensible text editors out there. It’s been around for more than 30 years and it’s also “free as in freedom” software, meaning among other things that you can customize it to your liking and share those customizations with communities of dedicated peers. Those customizations are the predecessors of things like “preferences” and “settings” menus on most software. Whereas the latter still lock you in by giving you a few options to choose from, with Emacs sky is the limit.
Once you switch to Emacs and realize that the world of super file conversion is at your fingertips with Pandoc, you can write text in the simplest of interfaces and convert it to any of the 40 or so different export formats Pandoc handles. If you write in Markdown, this will give you incredible flexibility. No more fussing with style formatting on any text editor.
First Steps
If you use Linux or Mac OS, Emacs comes pre-installed and all you have to do is call it via Terminal by typing
emacs
. From there, the best way to start with Emacs is to get familiar with navigation, basic commands, key bindings, adding and deleting text by running the tutorial and typing “C-h t, that is, Ctrl-h followed by t”.It will take time. The learning curve is steep if you compare this to Microsoft Word or any other graphical text editor. But once you get a few typing habits down and a few packages installed, it all starts going smoother and faster. You don’t have to reach for the mouse as often as you did, and you can start editing all sorts of documents out of one place. As I went on — and will keep — learning emacs, I realized typing with a different system meant I didn’t think the same way about things.
Choosing your Emacs
If you decide you like it, you can choose from any of the many Emacs distributions out there instead of your pre-installed version on Mac OS. I use Aquamacs. I like the way it behaves as an app in Mac OS, I like how it integrates the Mac OS spell-check, and I liked how it came with AUCTeX pre-installed (more on that later).
Pandoc
I’m not sure I would have switched to Emacs for my writing without Pandoc. This “swiss-army knife” of markup conversion does wonders. There are many ways to install it (I downloaded the package. If you’re not sure where it’s been installed once you did that type
which pandoc
on Terminal and it’ll give you its location in your system). And the commands running it are initially simple.Emacs For Os X
Going Further
If you’re in grad school, you’ll want to play with LaTeX and get initiated to the wonderful world of type-setting and layout. To do this download MacTeX — the full 3gb version, not the light one. This will get you playing with Emacs and Pandoc very nicely and in little time.
With more looking up online and figuring out, you’ll be able to create templates for every kind of writing and correspondance format you’ll need, and you’ll be able to change these templates however you see fit. This also means you’ll be able to distinguish content from format in new and powerful ways.
Emacs Mac Github
It doesn’t mean you have to forego proprietary software forever. But It’ll open up on ways you can create more thinking space for yourself, and on more than one way of doing things on a computer.