Skip to content

Latest commit

 

History

History
173 lines (138 loc) · 6.66 KB

emacs-mac.org

File metadata and controls

173 lines (138 loc) · 6.66 KB

Macintosh Configuration for Emacs

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

Key Bindings

Not going to use the Escape key as my Meta key … that is what the Option key should be:

(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'super)

Once upon a time, I thought I would get confused and hit a Mac-specific keybinding with the “Command” key in Emacs, so I used the mac-key-mode to turn a standard Emacs into a more Macintosh-specific application. However, I find my fingers behaving the exact opposite, as I often hit Option-b to jump back a word when typing in the search bar in my browser.

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

Ligatures in Code

With font that has symbolic ligatures, we can either use a prebuilt Mac Port (see this message) or use this code to set up particular programming symbols to trigger those symbols.

(if (fboundp 'mac-auto-operator-composition-mode)
    (mac-auto-operator-composition-mode)
  (let ((alist '((33 . ".\\(?:\\(?:==\\)\\|[!=]\\)")
                 (35 . ".\\(?:[(?[_{]\\)")
                 (38 . ".\\(?:\\(?:&&\\)\\|&\\)")
                 (43 . ".\\(?:\\(?:\\+\\+\\)\\|\\+\\)")
                 (45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
                 (47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
                 (58 . ".\\(?:[:=]\\)")
                 (59 . ".\\(?:;\\)")
                 (60 . ".\\(?:\\(?:!--\\)\\|\\(?:\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[/<=>|-]\\)")
                 (61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
                 (62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
                 (63 . ".\\(?:[:=?]\\)")
                 (92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
                 (94 . ".\\(?:=\\)")
                 (123 . ".\\(?:-\\)")
                 (124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
                 (126 . ".\\(?:[=@~-]\\)"))))
    (dolist (char-regexp alist)
      (set-char-table-range composition-function-table (car char-regexp)
                            `([,(cdr char-regexp) 0 font-shape-gstring])))))

These symbols are more prominent in all languages, as well as being a single character symbol (well, until you hit backspace on it):

https://github.com/tonsky/FiraCode/raw/master/showcases/all_ligatures.png

Dash

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

(use-package dash-at-point
  :ensure t
  :bind ("C-c d d" . dash-at-point-with-docset)
  :config
  (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")))

Brew and ls

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")

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