doomemacs/core/core-os-osx.el

115 lines
3.8 KiB
EmacsLisp
Raw Normal View History

2015-06-06 18:40:33 +08:00
;;; core-os-osx.el --- Mac-specific settings
2015-06-05 06:23:21 +08:00
;; Use a shared clipboard
(setq x-select-enable-clipboard t
select-enable-clipboard t
2015-08-23 11:42:42 +08:00
;; Prefixes: Command = M, Alt = A
mac-command-modifier 'meta
mac-option-modifier 'alt
2015-11-10 04:52:55 +08:00
;; sane trackpad/mouse scroll settings
2015-11-11 07:10:32 +08:00
mac-redisplay-dont-reset-vscroll t
2015-11-10 04:52:55 +08:00
mac-mouse-wheel-smooth-scroll nil
2016-03-06 13:44:22 +08:00
mouse-wheel-scroll-amount '(5 ((shift) . 2)) ; one line at a time
mouse-wheel-progressive-speed nil ; don't accelerate scrolling
2015-11-11 07:10:32 +08:00
2015-11-22 05:22:40 +08:00
;;; NOTE Meaningless to railwaycat's emacs-mac build
2015-06-05 06:23:21 +08:00
;; Curse Lion and its sudden but inevitable fullscreen mode!
ns-use-native-fullscreen nil
;; Don't open files from the workspace in a new frame
2015-11-10 04:52:55 +08:00
ns-pop-up-frames nil)
2015-06-05 06:23:21 +08:00
;; fix emacs PATH on OSX (GUI only)
2015-06-24 21:36:05 +08:00
(when window-system
2015-06-05 06:23:21 +08:00
(setenv "SHELL" "/usr/local/bin/zsh")
2015-11-24 04:22:13 +08:00
;; `exec-path-from-shell' is slow, so bring out the cache
(setq exec-path
(or (persistent-soft-fetch 'exec-path-env "osx")
(progn
(require 'exec-path-from-shell)
(exec-path-from-shell-initialize)
(persistent-soft-store 'exec-path-env exec-path "osx")
exec-path))))
2015-06-05 06:23:21 +08:00
;; Enable mouse support in terminal
(unless window-system
(require 'mouse)
(xterm-mouse-mode t)
2016-01-31 10:16:10 +08: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 13:44:22 +08:00
;;
;; OSX-related plugins + hacks
;;
2015-06-05 06:23:21 +08:00
(use-package dash-at-point
2016-02-21 04:30:30 +08:00
:commands (dash-at-point dash-at-point-with-docset dash-at-point-run-search dash-at-point-guess-docset)
:init
(defmacro define-docset! (mode docset)
2016-03-14 03:14:56 +08:00
`(add-hook! ,mode (setq-local dash-at-point-docset ,docset))))
2015-06-05 06:23:21 +08:00
(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
(defadvice evil-visual-update-x-selection (around clobber-x-select-text activate)
(unless (or (featurep 'mac) (featurep 'ns)) ad-do-it)))
2015-06-05 06:23:21 +08:00
2016-03-06 13:44:22 +08:00
;;
;; OS-integration
;;
2015-11-17 15:07:24 +08:00
2015-06-06 18:40:33 +08:00
(defun narf-open-with (&optional app-name path)
2015-06-15 15:05:52 +08:00
"Send PATH to APP-NAME on OSX."
2015-06-05 06:23:21 +08:00
(interactive)
2015-11-13 16:51:02 +08: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 16:51:02 +08:00
(format "'%s'" path)))))
2015-06-05 06:23:21 +08:00
(message "Running: %s" command)
(shell-command command)))
2015-12-09 15:05:00 +08:00
(defmacro open-with! (id &optional app dir)
`(defun ,(intern (format "os-%s" id)) ()
(interactive)
(narf-open-with ,app ,dir)))
(open-with! open-in-default-program)
(open-with! open-in-browser "Google Chrome")
(open-with! reveal "Finder" default-directory)
(open-with! reveal-project "Finder" (narf/project-root))
(open-with! upload "Transmit")
(open-with! upload-folder "Transmit" default-directory)
(open-with! send-to-launchbar "LaunchBar")
(open-with! send-project-to-launchbar "LaunchBar" (narf/project-root))
(defun os-switch-to-term ()
2015-10-01 01:49:37 +08:00
(interactive)
2015-11-17 15:07:24 +08:00
(do-applescript "tell application \"iTerm\" to activate"))
2015-10-01 01:49:37 +08:00
2015-12-09 15:05:00 +08:00
(defun os-switch-to-term-and-cd ()
2015-10-01 01:49:37 +08:00
(interactive)
2015-11-22 05:22:40 +08:00
(narf:send-to-tmux (format "cd %s" (shell-quote-argument default-directory)))
2015-11-13 16:51:02 +08:00
(narf-switch-to-iterm))
2015-10-01 01:49:37 +08:00
;; Open with external programs
2016-03-06 13:44:22 +08: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 18:49:05 +08:00
2015-06-06 18:40:33 +08:00
(provide 'core-os-osx)
;;; core-os-osx.el ends here