Move :tools macos to :os macos

This commit is contained in:
Henrik Lissner 2020-08-20 02:10:25 -04:00
parent 7081d833f6
commit f4ec42ae5c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
8 changed files with 117 additions and 51 deletions

View file

@ -0,0 +1,42 @@
#+TITLE: os/macos
#+DATE: February 19, 2017
#+SINCE: v1.3
#+STARTUP: inlineimages nofold
* Table of Contents :TOC_3:noexport:
- [[#description][Description]]
- [[#module-flags][Module Flags]]
- [[#maintainers][Maintainers]]
- [[#plugins][Plugins]]
- [[#features][Features]]
- [[#open-with-x]["Open with X"]]
* Description
This module provides extra functionality for macOS.
** Module Flags
This module provides no flags.
** Maintainers
This module has no dedicated maintainers
** Plugins
+ [[https://github.com/emacsorphanage/osx-trash][osx-trash]]
+ [[https://github.com/purcell/ns-auto-titlebar][ns-auto-titlebar]]
* Features
** "Open with X"
This module adds various macOS-specific launchers under the =SPC o= prefix (=C-c
o= for users with Evil disabled).
It also enables Keychain integration for =auth-source=. This is used by our [[file:../../../modules/app/irc/README.org][irc]]
and [[file:../../../modules/tools/magit/README.org][magit]]-forge modules, for instance.
To support GitHub Forge add an internet password like this to your keychain:
| Field | Value |
|----------+-------------------------|
| Name | api.github.com |
| Kind | Internet password |
| Account | <username>^forge |
| Where | https://api.github.com/ |
| Password | <token> |

View file

@ -0,0 +1,51 @@
;;; os/macos/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +macos-open-with (&optional app-name path)
"Send PATH to APP-NAME on OSX."
(interactive)
(let* ((path (expand-file-name
(replace-regexp-in-string
"'" "\\'"
(or path (if (derived-mode-p 'dired-mode)
(dired-get-file-for-visit)
(buffer-file-name)))
nil t)))
(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)))
;;;###autoload
(defmacro +macos--open-with (id &optional app dir)
`(defun ,(intern (format "+macos/%s" id)) ()
(interactive)
(+macos-open-with ,app ,dir)))
;;;###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"
(or (doom-project-root) default-directory))
;;;###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"
(or (doom-project-root) default-directory))
;;;###autoload (autoload '+macos/open-in-iterm "os/macos/autoload" nil t)
(+macos--open-with open-in-iterm "iTerm" default-directory)

View file

@ -0,0 +1,62 @@
;;; os/macos/config.el -*- lexical-binding: t; -*-
;;
;;; Reasonable defaults for macOS
;; Use spotlight search backend as a default for M-x locate (and helm/ivy
;; variants thereof), since it requires no additional setup.
(setq locate-command "mdfind")
;;
;;; Compatibilty fixes
;; Curse Lion and its sudden but inevitable fullscreen mode!
;; NOTE Meaningless to railwaycat's emacs-mac build
(setq ns-use-native-fullscreen nil)
;; Visit files opened outside of Emacs in existing frame, not a new one
(setq ns-pop-up-frames nil)
;; sane trackpad/mouse scroll settings
(setq mac-redisplay-dont-reset-vscroll t
mac-mouse-wheel-smooth-scroll nil)
;; Sets `ns-transparent-titlebar' and `ns-appearance' frame parameters so window
;; borders will match the enabled theme.
(and (or (daemonp)
(display-graphic-p))
(require 'ns-auto-titlebar nil t)
(ns-auto-titlebar-mode +1))
;; HACK On MacOS, disabling the menu bar makes MacOS treat Emacs as a
;; non-application window -- which means it doesn't automatically capture
;; focus when it is started, among other things. We enable menu-bar-lines
;; there, but we still want it disabled in terminal frames because there it
;; activates an ugly menu bar.
(add-hook! '(window-setup-hook after-make-frame-functions)
(defun doom-init-menu-bar-in-gui-frames-h (&optional frame)
"Re-enable menu-bar-lines in GUI frames."
(when-let (frame (or frame (selected-frame)))
(when (display-graphic-p frame)
(set-frame-parameter frame 'menu-bar-lines 1)))))
;; Integrate with Keychain
(after! auth-source
(pushnew! auth-sources 'macos-keychain-internet 'macos-keychain-generic))
;;
;;; Packages
(use-package! osx-trash
:commands osx-trash-move-file-to-trash
:init
;; Delete files to trash on macOS, as an extra layer of precaution against
;; accidentally deleting wanted files.
(setq delete-by-moving-to-trash t)
;; Lazy load `osx-trash'
(and IS-MAC
(not (fboundp 'system-move-file-to-trash))
(defalias #'system-move-file-to-trash #'osx-trash-move-file-to-trash)))