11

I can use emacs commands everywhere on macOS, which is good. But why? For example, in forms in Safari, I can use ctl-a, ctl-k, etc... I can use them in Note.app, too.

My guess is they are actually Unix commands and emacs borrowed them?

bmike
  • 235,889

3 Answers3

10

I can use emacs commands everywhere on macOS, which is good. But why?

Normally, asking “Why Apple does this, that, or the other thing” would be considered off topic, however, this one actually has an answer based in history.

The short answer to this is because the Emacs keybindings support is implemented in the Cocoa Text System.

My guess is they are actually Unix commands and emacs borrowed them?

They are not, however, Unix commands, because already pointed out in another answer, they are not found in the Unix specification. Also, they are not “universal” and cannot be used everywhere. They can only be used where the application(s) make use of the Cocoa Text System. For example, they cannot be used in Microsoft Word.

So, what does Cocoa have to do with anything? Well, Cocoa is derived from OpenStep which was a project developed by NeXT and Sun Microsystems to provide a NeXTSTEP like environment to non-NeXTSTEP operating systems. NeXT produced an OpenStep variation for its own Mach-based Unix.

Now remember, the macOS Unix kernel is Mach-based.

So, how did Apple get its hands on Mach and OpenStep? Well, on February 7, 1997 Apple acquired NeXT (along with Steve Jobs). The derivative products from that purchase was, you guessed it, macOS based on the Mach kernel, OpenStep, and all the other goodies NeXT had in their portfolio.

So, why did Apple bring over all those keybindings as they developed Cocoa? It only made sense for Apple bring over an environment developers (lots and lots of them from the Unix-verse) were already familiar with. Cocoa, derived from OpenStep, implemented the Emacs functionality already built into OpenStep.

Allan
  • 101,432
1

Your guess is not really correct, no. These "commands" (or keyboard shortcuts) are not Unix-commands. The Unix specification does not say anything about system wide text editing short cuts or similar, so you cannot really say that it is borrowed from there.

I doubt that the answer from @ankii is correct either. It doesn't make sense that "for consistent design" you would have two different short cuts for each of many operations (such as for example Ctrl-A you mentioned having the probably more Mac-ish shortcut Cmd-LeftArrow).

Another thought could be that emacs actually borrowed these short cuts from macOS. This is not the case either. Emacs originated in 1976, while the first Macintosh System Software release is from 1984.

The most logical explanation would be that some or many macOS system programmers from an early time were users of editors with command short cuts similar to emacs (which would include emacs itself), or that a large enough subset of initial customers were such users - so they added on these extra short cuts for everyone to feel at home.

In fact some of these short cuts date back quite a lot. As far as I know, they originate with the "computer terminals" that were the way many large computer systems were accessed in the 1970s. In rough terms, terminals are the evolutionary step after "line printers" as the main interface, and before "bitmap displays" (computer monitors).

For example the popular VT100 series of virtual terminals (circa 1978) came with similar short cuts. For example similar to Control-K in macOS, Escape-K deleted to the end of line. Note that in those days, the ESC-key was not located on the keyboard where it is today.

jksoegaard
  • 77,783
  • http://www.hcs.harvard.edu/~jrus/Site/cocoa-text.html, as outdated as it partially is, has more about the similarity of macOS key bindings and Emacs. – nohillside Dec 27 '19 at 22:47
  • 1
    Emacs was the preferred editor for most early Apple engineers as opposed to vi hence the convention being established In cocoa SDK shortcuts. Both these editors predate Apple. Using the common libraries and having them rich and consistent is the defining characteristics of macOS imo. – bmike Dec 27 '19 at 22:48
  • I don't know if you could really say that they predate Apple - I would say they are contemporaries. Apple was founded in April 1976, whereas vi was first a thing later that year. Similarly the first editor called EMACS is from late 1976. As I already wrote in my answer, they definitely predate the Macintosh OS. – jksoegaard Dec 27 '19 at 22:59
  • I meant " consistent design" to imply consumer satisfaction and ease of use. This is possible on both Apple and Emacs' end. " ... it should not redefine the key to do something else as it would potentially confuse users." wiki – anki Dec 28 '19 at 06:14
  • Many CTRL-based shortcuts have their origin in ASCII non-printing characters, used as commands. – benwiggy Dec 28 '19 at 13:19
  • @benwiggy Do they really? - It doesn't seem to be the case with the keyboard shortcuts we talk about here. For example - the short cuts mentioned in the question, they haven't got any resemblance to ASCII at all. I.e. Ctrl-K on macOS deletes the line of the line, while in ASCII it means vertical tab. Similarly Ctrl-A on macOS means move the cursor to the start of the line, while in ASCII it means that header data follows. Other examples: Ctrl-E is move to end of line in macOS, while it is a kind of "keep alive" in ASCII. Ctrl-O is insert line in macOS, while it's "change color" in ASCII. – jksoegaard Dec 28 '19 at 15:42
  • One of the only ones that actually match are Ctrl-H which is backspace in ASCII, and essentially deletes the previous character in macOS. – jksoegaard Dec 28 '19 at 15:43
  • @jksoegaard Fair enough! – benwiggy Dec 28 '19 at 16:47
  • 1
    Also the emacs bindings solved a problem for "which key sequences to use in a non-model editing environment" early enough to become a semi-standard. I believe for browsers it came from Netscape which for the Unix version was coded by jwz who is an expert Emacs programmer (his work became XEmacs) – Thorbjørn Ravn Andersen Dec 29 '19 at 12:42
  • @ThorbjørnRavnAndersen I was going to say that they NeXT use of keys predates Netscape but then I realized that the original web browser had these key short cutas it was coded in NeXTSTEP. So Netscape just followed existing ways:) – mmmmmm Dec 30 '19 at 11:58
  • @user151019 As I remember Netscape was "NCSA Mosaic" done as a product, and many of the Mosaic programmers were hired to implement it. According to https://en.wikipedia.org/wiki/Mosaic_(web_browser)#History Mosaic was not based on any more than a demo of the original web browser, so I would be hesitant to say that this was the reason. It might however be, that the text box widget used by Mosaic had these keybindings and that set the future standard. – Thorbjørn Ravn Andersen Jan 01 '20 at 19:32
0

One can see most of the shortcuts on macOS at https://support.apple.com/en-us/HT201236 and https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts

As for why you can use them in emacs, it could be for consistent design, like the four or five tabs in so many iOS apps.

anki
  • 11,753