Skip to content

Latest commit

 

History

History
177 lines (138 loc) · 6.07 KB

emacs-mac.org

File metadata and controls

177 lines (138 loc) · 6.07 KB

Macintosh Configuration for Emacs

The settings in this file are only included on a Macintosh, and even then, only during a graphical run.

Needed Packages

(packages-install '( mac-key-mode ))

Key Bindings

I like the ability to use the Command key to turn a standard Emacs into a more Macintosh-specific application. (See these online notes)

(setq mac-option-modifier 'meta)

;; Emacs on Mac specific code:
(unless (boundp 'aquamacs-version)
  (require 'mac-key-mode)
  (mac-key-mode)

  (define-key mac-key-mode-map (kbd "A-o") 'ido-find-file)

  ;; I'd rather selectively bind Meta-I to my italics function,
  ;; instead of showing the file in the Finder.
  (define-key mac-key-mode-map (kbd "A-i") nil)
  (define-key mac-key-mode-map (kbd "A-2") 'mac-key-show-in-finder)

  (define-key mac-key-mode-map (kbd "A-+") 'text-scale-increase)
  (define-key mac-key-mode-map (kbd "A-_") 'text-scale-decrease)
  (define-key mac-key-mode-map (kbd "A-l") 'goto-line)

  ;; Command-Q is awful (too easy to hit) ... especially next to
  ;; the more benign key binding to close a window: Cmd-W
  (define-key mac-key-mode-map (kbd "A-q") 'dont-kill-emacs)

  (define-key mac-key-mode-map (kbd "A-w") 'bury-buffer)
  (define-key mac-key-mode-map (kbd "A-M-w") 'kill-this-buffer))

Since the default ls for the Mac isn’t so good, I always have the GNU ls version available in /usr/local/bin/gls.

(require 'ls-lisp)
(setq ls-lisp-use-insert-directory-program t)
(setq insert-directory-program "/usr/local/bin/gls")

I hate the default implementation of Command-M. Now, pressing Command-M will toggle whether the Option key is a standard Option key or a Meta key:

(defun toggle-meta-key ()
  "Toggles whether the Mac option key is an option key or a meta key."
  (interactive)
  (if (eq mac-option-modifier 'meta)
      (setq mac-option-modifier nil)
    (setq mac-option-modifier 'meta)))

Undo and Redo

Special Cmd-Z binding for the special undo world.

(unless (boundp 'aquamacs-version)
  (define-key mac-key-mode-map (kbd "A-z") 'undo-tree-undo)
  (define-key mac-key-mode-map (kbd "A-S-z") 'undo-tree-redo))

Dash

The Dash product is nice, and this project allows Emacs to open Dash for documentation of anything with a C-c d keystroke:

(autoload 'dash-at-point "dash-at-point"
  "Search the word at point with Dash." t nil)
(global-set-key (kbd "C-c d") 'dash-at-point)
(global-set-key (kbd "C-c e") 'dash-at-point-with-docset)

Let’s tie some of my most-used language modes with particular docsets:

(add-to-list 'dash-at-point-mode-alist '(clojure-mode . "clojure"))
(add-to-list 'dash-at-point-mode-alist '(ruby-mode . "ruby"))
(add-to-list 'dash-at-point-mode-alist '(python-mode . "python2"))
(add-to-list 'dash-at-point-mode-alist '(sh-mode . "bash"))
(add-to-list 'dash-at-point-mode-alist '(emacs-lisp-mode . "elisp"))

Notifications

Looking at making some processes a bit more obvious, for instance, when a command kicked off in the eshell takes too much time, I need it to beep when it is done. For this, I simply shell out to Mac’s notification center using the terminal-notifier. To install, do:

brew install terminal-notifier

The beep command can either be typed at the end of a command (after a semi-colon), or at the beginning, since anything following is executed first, and the notification follows.

(defun eshell/beep (&rest args)
  "Send a Mac notification message when the command given has
completed."

  (let ((comment (if args
                     (concat "Process has completed: " (car args))
                   "Process has completed.")))
    (if args
        (eshell-plain-command (car args) (cdr args)))

    (shell-command-to-string
     (concat "terminal-notifier -message '"
             comment
             "' -title 'Emacs' -subtitle 'Eshell Process Completed'"
             " -sound default -sender org.gnu.Emacs"))))

Skype

I normally mute Skype with some Alfred keystroke running some AppleScript. However, Emacs will grab all keystrokes before passing them on, so I need this function:

 (defun mute-skype ()
   "Mutes or unmutes Skype via an AppleScript call."
   (interactive)
   (let ((mute-script "tell application \"Skype\"
  if \(send command \"GET MUTE\" script name \"MuteToggler\"\) is equal to \"MUTE ON\" then
    send command \"SET MUTE OFF\" script name \"MuteToggler\"
  else
    send command \"SET MUTE ON\" script name \"MuteToggler\"
  end if
end tell"))
     (progn
       (call-process "osascript" nil nil nil "-ss" "-e" mute-script)
       (message "Skype (un)mute message has been sent."))))

(global-set-key (kbd "C-M-A-m") 'mute-skype)

Technical Artifacts

Make sure that we can simply require this library.

(provide 'init-mac)

Before you can build this on a new system, make sure that you put the cursor over any of these properties, and hit: C-c C-c