Emacs для mac os

Emacs For Mac OS

Binaries for OS X

The official Emacs fully supports Mac OS X (along with GNU/Linux, Windows, DOS, and then some). You can find precompiled versions of emacs and Emacs.app at http://emacsformacosx.com/.

Versions of macOS prior to 10.15 Catalina include a copy of GNU Emacs 22 without GUI support compiled in and thus Emacs is automatically available on all but the most recent versions of macOS via the terminal. On macOS 10.15 Catalina and higher, mg (previously known as microGNUemacs) is still included. However, there are other Emacs distributions geared towards macOS that include GUI support as well as other features that may make it a more appropriate choice for some, if not most people.

Cocoa is the Objective-C API (originally developed by NeXT) that is used for native OS X applications (included in Emacs 23.2). Aquamacs and Emacs.app (which was merged into the official Emacs as of Emacs-23) both run under Cocoa. Note that Emacs.app, GNU Emacs/Cocoa, and GNU Emacs/nextstep refer to the same thing.

Carbon is the C language API (developed by Apple) that lets applications written under OS 9 (or earlier) run under OS X. Carbon Emacs runs under Carbon. As of Emacs 23, Carbon Emacs has been deprecated in favor of Emacs.app.

X11 Emacs is the “original” emacs running under X11 (installed by default in recent versions of Mac OS X)

If you are a Mac user new to Emacs, many people find Aquamacs to be a good choice. Many find it to be more Mac-like than Emacs.app. If you’ve used Emacs before and already have your own Emacs initialization file, then Emacs.app is likely a better choice.

As compared to Aquamacs, Emacs.app is more traditional in its approach, prefers a single frame, and is more likely to work with existing emacs initialization files. 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=en_GB.utf-8 LC_ALL=en_GB.utf-8 or PATH= for sub-applications launched from Emacs like R, Octave, Gnuplot etc., set the environments not only in .bash_profile but in .bashrc and try (since Yosemite /etc/launchd.conf is no more consulted for security reasons).

If you are looking for more integration with OSX, Mitsuharu Yamamoto’s Mac port might be the best option. It adds valuable smooth scrolling and subpixel font rendering not found elsewhere. Other than that is it stock standard emacs.

OS X Binary Vanilla builds

These builds are based on the development version of GNU Emacs and do not contain any additional packages or patches. Popular Mac keyboard shortcuts are available though (e.g. Command-O for opening a file); these are mapped to the Super modifier (i.e., the Apple/Command key functions as Super).

OS X Distributions with extras

Custom distributions contain startup routines and tweaks to make Emacs’ UI behavior more “Mac-like”. In addition to that, they typically include recent versions of popular packages.

Building Emacs From Source

Getting the Source

To download emacs using git, use this command:

Tarball

Available from the GNU Savannah emacs page. Click on “Download Area” under “Quick Overview”.

Building Emacs for OS X, using the normal GUI

There are many options for building emacs (such as whether to build for the X11 GUI or the Cocoa GUI), which are discussed in the INSTALL file. There is also a script (emacs/mac/make-package) to create a Mac OS X package for use by the installer.

To build Emacs under Mac OS X:

When the build is complete, you should see Emacs.app in ./nextstep/Emacs.app. Simply copy it to your applications folder and open it to run.

Читайте также:  Встроенный антивирус windows defender

For more detailed instructions, see the nextstep/INSTALL file. Additionally, you may benefit from reading the build script here: http://github.com/ieure/emacs-nightly.

As of October 2011, the version of autoconf on OS X Lion is not recent enough to configure/compile Emacs from source. There is a workaround provided by using the autogen/copy_autogen script which will build emacs using pre-generated versions of the required build files. See the comments in autogen/copy_autogen for more information.

Aquamacs

AquamacsEmacs can be built via build script or manually. The source is available from a Git repository. Then, do:

When the build is complete, find Aquamacs.app in .nextstep.

Note: changes to any source files in src/ require a simple “make”. The binary will directly be installed into nextstep/Aquamacs.app. Changes to source files in lisp/ require a “make install”. Changes to any lisp files directly in the .app bundle may or may not take effect (upon restarting Aquamacs): for many such files (list lisp/site-load.el), you must call “make”.

Detailed build instructions are available on BuildingAquamacs.

X11 Emacs

Directions to build and install may be found in the INSTALL or INSTALL.REPO files. The basic build and installation of the X11 Emacs application uses the commands:

Carbon Emacs (for Emacs /usr/local/Cellar/emacs/*/Emacs.app to /Applications/ from Finder. Or:

After installation, using the emacs command in the terminal defaults to opening Emacs.app in a new window, separate from the terminal. This represents a change in behaviour from the version of emacs pre-installed on macOS 10.14 and earlier. If you want to run emacs in the terminal then it must be invoked with the -nw “non-windowed” flag. You are required to configure environment variables (EDITOR and/or VISUAL), shell profiles (.bash_profile) and other configuration files (.git_config) to invoke emacs -nw if this is your desired default.

Emacs-Plus version in tap

To instead use the emacs-plus version, which is like regular homebrew emacs but with some configuration options enabled,

Mitsuharu version in tap

To instead use the Yamamoto Mitsuharu version of Emacs (27.1 as of 2020-11) (with more mac-specific features):

and finally link it to your Applications folder (default Homebrew App location):

MacPorts

MacPorts http://www.macports.org/ is another means of installing Emacs on Mac OS X or macOS (and even other Unix-like systems for that matter which MacPorts also supports).

As of March 1, 2021 it provides the following packages:

  • emacs 27.1
  • emacs-app 27.1
  • emacs-mac-app 8.1
  • xemacs 21.4.22
  • and quite a few more…

See Available Ports for the current list.

The emacs executable installs to: /opt/local/bin/emacs

The emacs-app executable installs to: /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs

The various emacs packages MacPorts offers (e.g., org-mode) will install to: /opt/local/share/emacs/site-lisp/

Note that Mac OS–X Lion comes with GNU Emacs 22.1.1, located at: /usr/bin/emacs

Linux users, add these lines to your .profile (or .bashrc, etc.) to feel at home:

For the OS X native (Cocoa) versions, once you’ve got MacPorts installed, run

or (if you prefer a – usually more recent– development version)

It’s also possible to build the development version of GNU Emacs with ATSUI – Apple Type Services for Unicode Imaging.

Mitsuharu version in MacPorts

To instead use the Yamamoto Mitsuharu version of Emacs (27.1 as of 2020-11) (with more mac-specific features):

The application will appear in your Applications/MacPorts folder.

Terminal Emulation

Read up on iTerm2 if you want to spend most of your time in ssh using emacs rather than the GUI.

Visit Mac files with native Mac app in dired

Use the shell mode. Make sure cursor is at the file, then type: ! open

Using the GUI Emacs.app from the command line.

To —debug-init if you installed the Emacs.app from Macports:

To open a file from a terminal. This can be used in combination with the sudo command.

As above but for when Emacs.app has been installed via MacPorts.

Call Emacs from other programs

Insert this into the .bash_profile file in your home directory:

Unlike “open -a”, this command will open a new window, and won’t terminate until you close the window (C-x C-c). So, the calling program will wait until you’ve finished editing, before it reads the file. For example, change control programs like git and svn will call emacs to edit your description of a change.

Using Emacs.app from the Dock

Create an app that runs a shell script that runs Emacs.app, like this: use Finder to navigate to /Applications and double-click Automator.app. Select the document type “Application” and click “Choose”. In the list on the left, select “Library”. In the next list, find “Run Shell Script” and drag it into the workflow area on the right. In the new shell script, delete the text and replace it with:

Select “Shell: /bin/bash” and “Pass input: as arguments”. Click “File > Save…” and choose a name and location for your new app. For example, you might choose the /Applications directory and name the app “Emacs for Dock.” Don’t replace Emacs.app.

Читайте также:  Как поставить звук по умолчанию windows 10

If you like, you can change your new app’s icon to match Emacs.app, like this: select Emacs.app and right-click “Get Info” or press cmd+i. In the info window, select the small icon in the top left corner and copy it (cmd+c). Next, select your new application, get its info, select the small icon and paste (cmd+v).

Drag your new app into the Dock as usual, and you’re good to go.

Your new app does two things that the Dock doesn’t (on Mac OS 10.9). The “cd” command causes emacs to start in your home directory, instead of the root directory “/”. The —login option gives emacs the same environment as an interactive Terminal. In particular, it gives emacs your usual PATH environment variable, so you can run commands in emacs the same as commands in Terminal. An alternative to —login is -i, which sets the environment differently, as described in the Bash reference manual.

If you followed above guide, and registered the app to the dock, and clicked it, it will actually create another icon in the dock for the running Emacs application. After that, if you click the original app icon, it will not create another running app in the Dock, but the Automator might spin infinitely, as you already have it (as in the second app icon).

If you’re using “M-x server-start”, then you could use following script instead above one:

Above script is tested in Aquamacs, but it may work with Emacs. What it does, if you click the original App Icon twice, it will just give the focus to the Emacs(Aquamacs), and if you drag a file to it, it will call emacsclient to transfer it to the Emacs process. If there is no Emacs process, it will create it. – CinSK

If you want the Automator gear to stop spinning, try replacing the two lines between the last else and fi with

Use Alt/Option as Meta Key under terminal emulators

For Terminal.app, starting from Snow Leopard: Go to Preferences > Settings > Keyboard > Use option as meta key. Starting from El Capitan (or maybe earlier): Go to Preferences > Profiles > Keyboard > Use Option as Meta Key.

For iTerm: Go to Manage Profiles > Keyboard profiles > (your profile) > Option Key as… For iTerm2: Go to Preferences > Profiles > Keys > Left/Right option key acts as: Meta

If you want to use Option key for both international characters and Meta key in Emacs, see this page for iTerm 0.10.x patch and/or binary.

Alt-b and Alt-f for navigating by word also works for your shell now.

Use Left Command as Meta Key under iTerm2 terminal emulator

  1. In iTerm2 go to Preferences > Keys
  2. Under Remap Modifier Keys, change Left Command Key to behave like Right Option
  3. Then go to Preferences > Profiles > $YourProfile > Keys
  4. On the bottom right of the screen click “Right option key acts as: +Esc”

Call AppleScript from Emacs

I use Andrew Choi’s build of GNU Emacs at work every day on OS X. I keep some notes and some Lisp functions for calling AppleScript from Emacs in my advogato.org diary:

Encoding for Terminal.app on OS X

The OS X Terminal.app uses UTF-8 by default. To get the correct behaviour from the Emacs that comes with OS X, I use the following settings in my InitFile file:

you also can write accents like this C-x 8 ‘ character see C-x 8 C-h

This also works with XEmacs 21.5.9 and above, at least.

  • Ctrl-Up and Ctrl-Down in shell-mode

In shell-mode, the [C-up] and [C-down] key-bindings do not work as expected to browse the history ring. The problem is that Terminal.app does not properly send these control sequences. To fix this behavior, open Terminal.app Preferences>>Settings>>Keyboard. Select the “+” button and you will see that you can add bindings to the “cursor down” key with the “control” modifier. Select “send string to shell”, and enter “ESCp”, i.e., emacs M-p. Similarly, define control cursor up to send “ESCn” to the shell.

Binding modifier keys

The variables available for binding the modifier keys:

values can be ‘control, ‘alt, ‘meta, ‘super, ‘hyper, nil (setting to nil allows the OS to assign values)

Example to bind the mac-right-option-modifier to ‘none so you can still use it to write accents:

Emacs keybindings in Cocoa Apps

This information does not regard the actual use of emacs, but I think many people will be happy to find out that some cursor movement / text editing keybindings can be used in Cocoa Apps. If you ever happen to use any other application on your Mac … You can also set up additional keybindings as described in this document.

http://www.lorax.com/FreeStuff/TextExtras.html provides additional Emacs like features to every Cocoa application like alt-/ completion

Читайте также:  Maven windows 10 download

Emacs keybindings in Terminal

So control-s is just beeping at me in emacs in the Mac OS X Terminal (10.4) on my home machine but works fine on 10.2 on my work machine – what gives? I’ve looked into the flow control tty issue and tried to disable it – still emacs just sits there beeping. M-x save-buffers and M-x isearch gets to be a pain. Any hints for the Mac OS X Terminal?

Say I want to run the function “forward-sexp” bound to C-M-f. I should be able to get at it with “hold ctrl, hold alt, hit f”. However, if I actually do that I get the result of the command forward-word (M-f). To actually get forward-sexp I must “hit esc, hold ctrl, hit f”. However the alt key works fine as meta for things like M-x and basically anything that doesn’t also require ctrl. Anyone know how to fix this? (This is using Terminal.app on 10.4.9 btw).

See the following blog post for swapping the cmd and meta key. Also, if you want to retain one of the Option key functions as modifier for national characters, see this page for iTerm patch and/or binary.

Emacs full disk access on Catalina / Big Sur

Recent macOS versions require you to separately give Emacs (and Terminal!) access to your disk.

GNU Emacs for OSX runs a Ruby wrapper, so you actually have to grant full disk access both to Emacs and to /usr/bin/ruby.

Emacs Keybindings under X11

See the following blog post for using alt as your meta key:

Use macOS default shortscuts for Cut/Copy/Paste/Select All

If you want to use the default shortcuts for copy, paste, cut etc. macOS, put this is your .init.el. Since M-x is overwritten in line 2, don’t forget to reassign it. See the last line as an example.

Maximize Emacs 23.3 and 24+ in Mac OS X Lion

Fullscreen mode is not offered in either 23.3 or 24+. In trying to adapt the “maximize-frame” function below I inadvertently discovered that if one uses the maximize control button once the frame is maximized vertically, twice the frame is maximized both vertically and horizontally and three times results in the frame restored to its original size. Good enough for me!

Enable / Disable Anti-Aliasing

To turn on/off anti-aliasing, use the following commands. By default, anti-aliasing is on.

For Emacs >= 24.4 and OS X >= 10.5, the default font backend has changed, and no longer supports these commands. The old backend can be used instead by running the following command in Terminal.app.

The commands will then work normally.

Another option is to use the following defaults command, which has some effect, but not as much as using the previous method.

To reverse the changes, use

Open emacsclient in a new iTerm tab from Mac’s Finder

Make fullscreen work with posframe.el

Don’t fullscreen frame when emacs starts, otherwise the macOS window manager will move emacs window to another single space, above code can make emacs just fullscreen frame in current space. —AndyStewart

Hacking on the Sources

The section is meant to collect useful hacks to the C sources (or to Lisp sources that are executed before any init files are read, such as startup.el ).

True fullscreen for the Cocoa build in Emacs 23

This fork has patches for true fullscreen and it works wonderfully.

Changing the Scrollbar Appearance

The size of the “knob” in a given window’s scrollbar is proportional to how much of the buffer is displayed in the window. When the whole buffer is displayed in the window, the knob takes up the entire scrollbar. I find this distracting (not to mention aesthetically objectionable), and much prefer the behavior of applications like iTerm that show an empty scrollbar slot in such cases.

You can get that effect in Emacs by making a small change to src/nsterm.m. Look for this bit of code:

and replace it with:

A further change is to have the knob be of constant, minimal size, so that it only indicates position in the buffer, instead of changing size according to the portion of the buffer displayed in the window (I find the variable sizes distracting). To do this, use the replacement code:

This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under any other license that grants the right to use, copy, modify, and/or distribute the work, as long as that license imposes the restriction that derivative works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.

Источник

Оцените статью