doomemacs/core/core-os-osx.el

109 lines
3.9 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
mouse-wheel-scroll-amount '(5 ((shift) . 2)) ;; one line at a time
2015-11-11 07:10:32 +08:00
mouse-wheel-progressive-speed nil ;; don't accelerate scrolling
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)
(global-set-key [mouse-4] (λ! (scroll-down 1)))
(global-set-key [mouse-5] (λ! (scroll-up 1)))
(defun track-mouse (e))
(setq mouse-sel-mode t))
2015-06-06 18:40:33 +08:00
;; OSX Related Plugins ;;;;;;;;;;;;;;;;;
2015-06-05 06:23:21 +08:00
(use-package dash-at-point
:commands (dash-at-point dash-at-point-with-docset)
:config
2015-11-09 06:58:00 +08:00
(mapc (lambda (r) (add-to-list 'dash-at-point-mode-alist r))
`((java-mode . "java,droid,javafx,grails,groovy,playjava,spring,cvj,processing,javadoc")
(scss-mode . ,(cdr (assoc 'sass-mode dash-at-point-mode-alist)))
)))
2015-06-05 06:23:21 +08:00
2015-06-06 18:40:33 +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
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
2015-11-19 18:49:05 +08:00
(defun narf-org-init-for-osx ()
;; Reveal files in finder
(setq org-file-apps '(("\\.org$" . emacs)
(t . "open -R \"%s\""))))
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