Skip to content

Commit

Permalink
Disable aerospace key binds when emacs is in front
Browse files Browse the repository at this point in the history
There are just too many bindings I really want to have in emacs.
The binding mode is also switched back to main when any other app's
window is in front.

This is my work-around for nikitabobko/AeroSpace#412
  • Loading branch information
eljobe committed Nov 2, 2024
1 parent f235cb2 commit 0707319
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 5 deletions.
8 changes: 8 additions & 0 deletions bin/executable_aero-focus.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/zsh
focused=$(aerospace list-windows --focused --format "%{app-bundle-id}")
if [[ "$focused" == "org.gnu.Emacs" ]]; then
aerospace mode emacs
else
aerospace mode main
fi
echo "" >> $LOG
7 changes: 7 additions & 0 deletions dot_config/aerospace/aerospace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ key-mapping.preset = 'qwerty'
# Fallback value (if you omit the key): on-focused-monitor-changed = []
on-focused-monitor-changed = ['move-mouse monitor-lazy-center']

on-focus-changed = ['exec-and-forget $HOME/bin/aero-focus.sh']

# Gaps between windows (inner-*) and between monitor edges (outer-*).
# Possible values:
# - Constant: gaps.outer.top = 8
Expand Down Expand Up @@ -168,6 +170,11 @@ cmd-alt-shift-down = ['join-with down', 'mode main']
cmd-alt-shift-up = ['join-with up', 'mode main']
cmd-alt-shift-right = ['join-with right', 'mode main']

# 'emacs' mode disables everything so emacs can have all the key bindings
[mode.emacs.binding]
# I'm not going to type this so it doesn't matter.
cmd-alt-shift-semicolon = 'mode emacs'

[[on-window-detected]]
if.app-id = 'com.tinyspeck.slackmacgap'
run = "move-node-to-workspace C"
Expand Down
172 changes: 167 additions & 5 deletions dot_config/emacs/init.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,21 @@
;; means that it just hard-codes the exec-path.
(setq load-path (cons "~/.config/emacs/lisp" load-path))
(load-library "path-fix")
;; Enable a vertical fuzzy command
(fido-vertical-mode)
;; Add prompt indicator to `completing-read-multiple'.
;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
(defun crm-indicator (args)
(cons (format "[CRM%s] %s"
(replace-regexp-in-string
"\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
crm-separator)
(car args))
(cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)

;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
:config
(put 'narrow-to-region 'disabled nil)
;; Make buffer names more useful
Expand Down Expand Up @@ -75,6 +88,157 @@
(tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
(typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
(yaml "https://github.com/ikatyang/tree-sitter-yaml")))
:custom
;; Support opening new minibuffers from inside existing minibuffers.
(enable-recursive-minibuffers t)
;; Hide commands in M-x which do not work in the current mode. Vertico
;; commands are hidden in normal buffers. This setting is useful beyond
;; Vertico.
(read-extended-command-predicate #'command-completion-default-include-p))

;; Enable vertical fuzzy completion in the minibuffer
(use-package vertico
:custom
;; (vertico-scroll-margin 0) ;; Different scroll margin
(vertico-count 20) ;; Show more candidates
;; (vertico-resize t) ;; Grow and shrink the Vertico minibuffer
;; (vertico-cycle t) ;; Enable cycling for `vertico-next/previous'
:init
(vertico-mode))

;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:init
(savehist-mode))

;; Set up a completion style that matches by words in any order.
(use-package orderless
:custom
;; Configure a custom style dispatcher (see the Consult wiki)
;; (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch))
;; (orderless-component-separator #'orderless-escapable-split-on-space)
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles partial-completion)))))

;; Enable integration between embark and consult
(use-package embark-consult)

;; Enable location-specific actions
(use-package embark)

;; Enable rich annotations
(use-package marginalia
;; Bind `marginalia-cycle' locally in the minibuffer. To make the binding
;; available in the *Completions* buffer, add it to the
;; `completion-list-mode-map'.
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle))
:init
(marginalia-mode))

;; Enable deep project-specific information
(use-package projectile
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("s-p" . projectile-command-map)
("C-c p" . projectile-command-map)))

;; Enable the best completion framework.
(use-package consult
;; Replace bindings. Lazily loaded by `use-package'.
:bind (;; C-c bindings in `mode-specific-map'
("C-c M-x" . consult-mode-command)
("C-c h" . consult-history)
("C-c k" . consult-kmacro)
("C-c m" . consult-man)
("C-c i" . consult-info)
([remap Info-search] . consult-info)
;; C-x bindings in `ctl-x-map'
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
("C-x t b" . consult-buffer-other-tab) ;; orig. switch-to-buffer-other-tab
("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
;; Custom M-# bindings for fast register access
("M-#" . consult-register-load)
("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
("C-M-#" . consult-register)
;; Other custom bindings
("M-y" . consult-yank-pop) ;; orig. yank-pop
;; M-g bindings in `goto-map'
("M-g e" . consult-compile-error)
("M-g f" . consult-flymake) ;; Alternative: consult-flycheck
("M-g g" . consult-goto-line) ;; orig. goto-line
("M-g M-g" . consult-goto-line) ;; orig. goto-line
("M-g o" . consult-outline) ;; Alternative: consult-org-heading
("M-g m" . consult-mark)
("M-g k" . consult-global-mark)
("M-g i" . consult-imenu)
("M-g I" . consult-imenu-multi)
;; M-s bindings in `search-map'
("M-s d" . consult-find) ;; Alternative: consult-fd
("M-s c" . consult-locate)
("M-s g" . consult-grep)
("M-s G" . consult-git-grep)
("M-s r" . consult-ripgrep)
("M-s l" . consult-line)
("M-s L" . consult-line-multi)
("M-s k" . consult-keep-lines)
("M-s u" . consult-focus-lines)
;; Isearch integration
("M-s e" . consult-isearch-history)
:map isearch-mode-map
("M-e" . consult-isearch-history) ;; orig. isearch-edit-string
("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
("M-s l" . consult-line) ;; needed by consult-line to detect isearch
("M-s L" . consult-line-multi) ;; needed by consult-line to detect isearch
;; Minibuffer history
:map minibuffer-local-map
("M-s" . consult-history) ;; orig. next-matching-history-element
("M-r" . consult-history)) ;; orig. previous-matching-history-element
;; Enable automatic preview at point in the *Completions* buffer. This is
;; relevant when you use the default completion UI.
:hook (completion-list-mode . consult-preview-at-point-mode)
:init
;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load',
;; `consult-register-store' and the Emacs built-ins.
(setq register-preview-delay 0.5
register-preview-function #'consult-register-format)
;; Optionally tweak the register preview window.
;; This adds thin lines, sorting and hides the mode line of the window.
(advice-add #'register-preview :override #'consult-register-window)
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
(autoload 'projectile-project-root "projectile")
(setq consult-project-function (lambda (_) (projectile-project-root)))
:config
;; Optionally configure preview. The default value
;; is 'any, such that any key triggers the preview.
;; (setq consult-preview-key 'any)
;; (setq consult-preview-key "M-.")
;; (setq consult-preview-key '("S-<down>" "S-<up>"))
;; For some commands and buffer sources it is useful to configure the
;; :preview-key on a per-command basis using the `consult-customize' macro.
(consult-customize
consult-theme :preview-key '(:debounce 0.2 any)
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file consult-xref
consult--source-bookmark consult--source-file-register
consult--source-recent-file consult--source-project-recent-file
;; :preview-key "M-."
:preview-key '(:debounce 0.4 any))
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; "C-+"
;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
)

(use-package windresize)
Expand Down Expand Up @@ -131,9 +295,7 @@
(defun elj-go-mode-hook()
(setq tab-width 2))
:hook (go-mode . elj-go-mode-hook)
:hook (before-save . gofmt-before-save)
:custom
(gofmt-command "goimports"))
:hook (before-save . gofmt-before-save))

(use-package rust-ts-mode
:mode "\\.rs\\'"
Expand Down

0 comments on commit 0707319

Please sign in to comment.