doomemacs/core/core-os-osx.el

127 lines
4.1 KiB
EmacsLisp
Raw Normal View History

2015-06-06 06:40:33 -04:00
;;; core-os-osx.el --- Mac-specific settings
2015-06-04 18:23:21 -04:00
2016-05-19 03:12:13 -04:00
(global-set-key (kbd "M-q") 'kill-emacs)
(setq ;; Prefixes: Command = M, Alt = A
2015-08-22 23:42:42 -04:00
mac-command-modifier 'meta
mac-option-modifier 'alt
2015-11-09 15:52:55 -05:00
;; sane trackpad/mouse scroll settings
2015-11-10 18:10:32 -05:00
mac-redisplay-dont-reset-vscroll t
2015-11-09 15:52:55 -05:00
mac-mouse-wheel-smooth-scroll nil
2016-03-06 00:44:22 -05:00
mouse-wheel-scroll-amount '(5 ((shift) . 2)) ; one line at a time
mouse-wheel-progressive-speed nil ; don't accelerate scrolling
2015-06-04 18:23:21 -04:00
;; Curse Lion and its sudden but inevitable fullscreen mode!
2016-05-21 23:12:50 -04:00
;; NOTE Meaningless to railwaycat's emacs-mac build
2015-06-04 18:23:21 -04:00
ns-use-native-fullscreen nil
;; Don't open files from the workspace in a new frame
2015-11-09 15:52:55 -05:00
ns-pop-up-frames nil)
2015-06-04 18:23:21 -04:00
2016-10-02 23:26:29 +02:00
;; On OSX, in GUI Emacs, `exec-path' isn't populated properly (it should match
;; $PATH in my shell). `exe-path-from-shell' fixes this.
2015-06-24 15:36:05 +02:00
(when window-system
2015-06-04 18:23:21 -04:00
(setenv "SHELL" "/usr/local/bin/zsh")
2015-11-23 15:22:13 -05:00
;; `exec-path-from-shell' is slow, so bring out the cache
(setq exec-path
2016-05-23 17:12:41 -04:00
(eval-when-compile
(require 'exec-path-from-shell)
(exec-path-from-shell-initialize)
exec-path)))
2015-06-04 18:23:21 -04:00
;; Enable mouse support in terminal
(unless window-system
(require 'mouse)
(xterm-mouse-mode t)
2016-01-30 21:16:10 -05:00
(global-set-key [mouse-4] (λ! (scroll-down 4)))
(global-set-key [mouse-5] (λ! (scroll-up 4)))
(defun track-mouse (e))
(setq mouse-sel-mode t))
2016-03-06 00:44:22 -05:00
;;
;; OSX-related plugins + hacks
;;
2015-06-04 18:23:21 -04:00
(use-package applescript-mode
:mode "\\.applescript$"
:init (add-hook 'applescript-mode-hook 'nlinum-mode)
:config
(def-docset! applescript-mode "applescript")
(after! quickrundb
(quickrun-add-command
"applescript" `((:command . ,as-osascript-command)
(:cmdopt . "-ss %s")
(:description . "Run applescript"))
:mode 'applescript-mode)))
2016-05-21 23:12:50 -04:00
(def-project-type! lb6 "lb6"
:match "\\.lb\\(action\\|ext\\)/.+$"
:build (lambda ()
(awhen (f-traverse-upwards (lambda (f) (f-ext? f "lbaction")))
(shell-command (format "open '%s'" it)))))
(after! evil
;; On OSX, stop copying each visual state move to the clipboard:
;; https://bitbucket.org/lyro/evil/issue/336/osx-visual-state-copies-the-region-on
;; Most of this code grokked from:
;; http://stackoverflow.com/questions/15873346/elisp-rename-macro
2016-04-26 02:00:19 -04:00
(when (or (featurep 'mac) (featurep 'ns))
(advice-add 'evil-visual-update-x-selection :override 'ignore)))
2015-06-04 18:23:21 -04:00
2016-03-06 00:44:22 -05:00
;;
2016-10-02 23:26:29 +02:00
;; OS-specific functions
2016-03-06 00:44:22 -05:00
;;
2015-11-17 02:07:24 -05:00
2016-05-20 22:37:30 -04:00
(defun doom-open-with (&optional app-name path)
2015-06-15 09:05:52 +02:00
"Send PATH to APP-NAME on OSX."
2015-06-04 18:23:21 -04:00
(interactive)
2015-11-13 03:51:02 -05:00
(let* ((path (f-full (s-replace "'" "\\'"
(or path (if (eq major-mode 'dired-mode)
(dired-get-file-for-visit)
(buffer-file-name))))))
(command (format "open %s"
(if app-name
(format "-a %s '%s'" (shell-quote-argument app-name) path)
2015-11-13 03:51:02 -05:00
(format "'%s'" path)))))
2015-06-04 18:23:21 -04:00
(message "Running: %s" command)
(shell-command command)))
(defmacro def-open-with! (id &optional app dir)
2015-12-09 02:05:00 -05:00
`(defun ,(intern (format "os-%s" id)) ()
(interactive)
2016-05-20 22:37:30 -04:00
(doom-open-with ,app ,dir)))
2015-12-09 02:05:00 -05:00
(def-open-with! open-in-default-program)
(def-open-with! open-in-browser "Google Chrome")
(def-open-with! reveal "Finder" default-directory)
2016-05-20 22:37:30 -04:00
(def-open-with! reveal-project "Finder" (doom/project-root))
(def-open-with! upload "Transmit")
(def-open-with! upload-folder "Transmit" default-directory)
(def-open-with! send-to-launchbar "LaunchBar")
2016-05-20 22:37:30 -04:00
(def-open-with! send-project-to-launchbar "LaunchBar" (doom/project-root))
2015-12-09 02:05:00 -05:00
(defun os-switch-to-term ()
2015-09-30 13:49:37 -04:00
(interactive)
2015-11-17 02:07:24 -05:00
(do-applescript "tell application \"iTerm\" to activate"))
2015-09-30 13:49:37 -04:00
2015-12-09 02:05:00 -05:00
(defun os-switch-to-term-and-cd ()
2015-09-30 13:49:37 -04:00
(interactive)
2016-05-20 22:37:30 -04:00
(doom:send-to-tmux (format "cd %s" (shell-quote-argument default-directory)))
(doom-switch-to-iterm))
2015-09-30 13:49:37 -04:00
2016-10-02 23:26:29 +02:00
;;
;; Plugins
;;
2016-03-06 00:44:22 -05:00
(use-package openwith
:config
(openwith-mode t)
(setq openwith-associations
'(("\\.\\(pdf\\|jpe?g\\|gif\\|docx?\\|pptx?\\|xlsx?\\|zip\\|tar\\(\\.gz\\)?\\|rar\\)$"
"open" (file)))))
2015-11-19 05:49:05 -05:00
2015-06-06 06:40:33 -04:00
(provide 'core-os-osx)
;;; core-os-osx.el ends here