From 80735a530b04bdb3b497208c3b854c37d64076a9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 31 Jan 2017 05:08:59 -0500 Subject: [PATCH] Add modules/os/macos --- modules/os/macos/autoload.el | 48 ++++++++++++++++++++++++++++++++++++ modules/os/macos/config.el | 35 ++++++++++++++++++++++++++ modules/os/macos/packages.el | 4 +++ 3 files changed, 87 insertions(+) create mode 100644 modules/os/macos/autoload.el create mode 100644 modules/os/macos/config.el create mode 100644 modules/os/macos/packages.el diff --git a/modules/os/macos/autoload.el b/modules/os/macos/autoload.el new file mode 100644 index 000000000..ebc194e25 --- /dev/null +++ b/modules/os/macos/autoload.el @@ -0,0 +1,48 @@ +;;; autoload.el + +;;;###autoload +(defun +macos-open-with (&optional app-name path) + "Send PATH to APP-NAME on OSX." + (interactive) + (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) + (format "'%s'" path))))) + (message "Running: %s" command) + (shell-command command))) + +(defmacro +macos--open-with! (id &optional app dir) + `(defun ,(intern (format "+macos/%s" id)) () + (interactive) + (+macos-open-with ,app ,dir))) + +;;;###autoload +(defun +macos/open-in-browser () + "Open current file in your default browser." + (interactive) + (browse-url buffer-file-name)) + +;;;###autoload (autoload '+macos/open-in-default-program "os/macos/autoload" nil t) +(+macos--open-with! open-in-default-program) + +;;;###autoload (autoload '+macos/reveal-in-finder "os/macos/autoload" nil t) +(+macos--open-with! reveal-in-finder "Finder" default-directory) + +;;;###autoload (autoload '+macos/reveal-project-in-finder "os/macos/autoload" nil t) +(+macos--open-with! reveal-project-in-finder "Finder" (doom-project-root)) + +;;;###autoload (autoload '+macos/send-to-transmit "os/macos/autoload" nil t) +(+macos--open-with! send-to-transmit "Transmit") + +;;;###autoload (autoload '+macos/send-cwd-to-transmit "os/macos/autoload" nil t) +(+macos--open-with! send-cwd-to-transmit "Transmit" default-directory) + +;;;###autoload (autoload '+macos/send-to-launchbar "os/macos/autoload" nil t) +(+macos--open-with! send-to-launchbar "LaunchBar") + +;;;###autoload (autoload '+macos/send-project-to-launchbar "os/macos/autoload" nil t) +(+macos--open-with! send-project-to-launchbar "LaunchBar" (doom-project-root)) diff --git a/modules/os/macos/config.el b/modules/os/macos/config.el new file mode 100644 index 000000000..f7bd0478c --- /dev/null +++ b/modules/os/macos/config.el @@ -0,0 +1,35 @@ + +(setq mac-command-modifier 'meta + mac-option-modifier 'alt + ;; sane trackpad/mouse scroll settings + mac-redisplay-dont-reset-vscroll t + mac-mouse-wheel-smooth-scroll nil + mouse-wheel-scroll-amount '(5 ((shift) . 2)) ; one line at a time + mouse-wheel-progressive-speed nil ; don't accelerate scrolling + ;; Curse Lion and its sudden but inevitable fullscreen mode! + ;; NOTE Meaningless to railwaycat's emacs-mac build + ns-use-native-fullscreen nil + ;; Don't open files from the workspace in a new frame + ns-pop-up-frames nil) + +(cond ((display-graphic-p) + ;; `exec-path-from-shell' is slow, so bring out the cache + (setq exec-path + (or (persistent-soft-fetch 'exec-path "emacs") + (persistent-soft-store + 'exec-path + (progn (require 'exec-path-from-shell) + (exec-path-from-shell-initialize) + exec-path) + "emacs")))) + (t + (require 'osx-clipboard) + (osx-clipboard-mode +1))) + +(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 + (when (or (featurep 'mac) (featurep 'ns)) + (advice-add 'evil-visual-update-x-selection :override 'ignore))) diff --git a/modules/os/macos/packages.el b/modules/os/macos/packages.el new file mode 100644 index 000000000..059d71ffe --- /dev/null +++ b/modules/os/macos/packages.el @@ -0,0 +1,4 @@ +;;; os/macos/packages.el + +(package! exec-path-from-shell) +(package! osx-clipboard)