<commit_before>;;; config/default/+bindings.el -*- lexical-binding: t; -*-

(when (featurep! :editor evil +everywhere)
  ;; NOTE SPC u replaces C-u as the universal argument.

  ;; Minibuffer
  (define-key! evil-ex-completion-map
    "C-a" #'evil-beginning-of-line
    "C-b" #'evil-backward-char
    "C-f" #'evil-forward-char
    "C-j" #'next-complete-history-element
    "C-k" #'previous-complete-history-element)

  (define-key! :keymaps +default-minibuffer-maps
    [escape] #'abort-recursive-edit
    "C-a"    #'move-beginning-of-line
    "C-r"    #'evil-paste-from-register
    "C-u"    #'evil-delete-back-to-indentation
    "C-v"    #'yank
    "C-w"    #'doom/delete-backward-word
    "C-z"    (λ! (ignore-errors (call-interactively #'undo))))

  (when (featurep! :editor evil +everywhere)
    (define-key! :keymaps +default-minibuffer-maps
      "C-f"    #'forward-word
      "C-b"    #'backward-word
      "M-f"    #'forward-char
      "M-b"    #'backward-char
      "C-j"    #'next-line
      "C-k"    #'previous-line
      "C-S-j"  #'scroll-up-command
      "C-S-k"  #'scroll-down-command)
    (define-key! read-expression-map
      "C-j" #'next-line-or-history-element
      "C-k" #'previous-line-or-history-element)))


;;
;;; Global keybindings

;; Smart tab, these will only work in GUI Emacs
(map! :i [tab] (general-predicate-dispatch nil ; fall back to nearest keymap
                 (and (featurep! :editor snippets)
                      (bound-and-true-p yas-minor-mode)
                      (yas-maybe-expand-abbrev-key-filter 'yas-expand))
                 #'yas-expand
                 (and (featurep! :completion company +tng)
                      (+company-has-completion-p))
                 #'+company/complete)
      :v [tab] (general-predicate-dispatch nil
                 (and (bound-and-true-p yas-minor-mode)
                      (or (eq evil-visual-selection 'line)
                          (not (memq (char-after) (list ?\( ?\[ ?\{ ?\} ?\] ?\))))))
                 #'yas-insert-snippet)

      ;; Smarter newlines
      :i [remap newline] #'newline-and-indent  ; auto-indent on newline
      :i "C-j"           #'+default/newline    ; default behavior

      (:after help :map help-mode-map
        :n "o"       #'link-hint-open-link)
      (:after helpful :map helpful-mode-map
        :n "o"       #'link-hint-open-link)
      (:after info :map Info-mode-map
        :n "o"       #'link-hint-open-link)
      (:after apropos :map apropos-mode-map
        :n "o"       #'link-hint-open-link
        :n "TAB"     #'forward-button
        :n [tab]     #'forward-button
        :n [backtab] #'backward-button)
      (:after view :map view-mode-map
        [escape]  #'View-quit-all)
      (:after man :map Man-mode-map
        :n "q"    #'kill-current-buffer)

      (:after (evil-org evil-easymotion)
        :map evil-org-mode-map
        :m "gsh" #'+org/goto-visible)

      (:when (featurep! :editor multiple-cursors)
        :prefix "gz"
        :nv "d" #'evil-mc-make-and-goto-next-match
        :nv "D" #'evil-mc-make-and-goto-prev-match
        :nv "j" #'evil-mc-make-cursor-move-next-line
        :nv "k" #'evil-mc-make-cursor-move-prev-line
        :nv "m" #'evil-mc-make-all-cursors
        :nv "n" #'evil-mc-make-and-goto-next-cursor
        :nv "N" #'evil-mc-make-and-goto-last-cursor
        :nv "p" #'evil-mc-make-and-goto-prev-cursor
        :nv "P" #'evil-mc-make-and-goto-first-cursor
        :nv "q" #'evil-mc-undo-all-cursors
        :nv "t" #'+multiple-cursors/evil-mc-toggle-cursors
        :nv "u" #'evil-mc-undo-last-added-cursor
        :nv "z" #'+multiple-cursors/evil-mc-make-cursor-here
        :v  "I" #'evil-mc-make-cursor-in-visual-selection-beg
        :v  "A" #'evil-mc-make-cursor-in-visual-selection-end)

      ;; misc
      :n "C-S-f"  #'toggle-frame-fullscreen
      :n "C-+"    #'doom/reset-font-size
      ;; Buffer-local font resizing
      :n "C-="    #'text-scale-increase
      :n "C--"    #'text-scale-decrease
      ;; Frame-local font resizing
      :n "M-C-="  #'doom/increase-font-size
      :n "M-C--"  #'doom/decrease-font-size)


;;
;;; Module keybinds

;;; :completion
(map! (:when (featurep! :completion company)
        :i "C-@"      #'+company/complete
        :i "C-SPC"    #'+company/complete
        (:after company
          (:map company-active-map
            "C-w"     nil  ; don't interfere with `evil-delete-backward-word'
            "C-n"     #'company-select-next
            "C-p"     #'company-select-previous
            "C-j"     #'company-select-next
            "C-k"     #'company-select-previous
            "C-h"     #'company-show-doc-buffer
            "C-u"     #'company-previous-page
            "C-d"     #'company-next-page
            "C-s"     #'company-filter-candidates
            "C-S-s"   (cond ((featurep! :completion helm) #'helm-company)
                            ((featurep! :completion ivy)  #'counsel-company))
            "C-SPC"   #'company-complete-common
            "TAB"     #'company-complete-common-or-cycle
            [tab]     #'company-complete-common-or-cycle
            [backtab] #'company-select-previous
            [f1]      nil)
          (:map company-search-map  ; applies to `company-filter-map' too
            "C-n"     #'company-select-next-or-abort
            "C-p"     #'company-select-previous-or-abort
            "C-j"     #'company-select-next-or-abort
            "C-k"     #'company-select-previous-or-abort
            "C-s"     (λ! (company-search-abort) (company-filter-candidates))
            [escape]  #'company-search-abort))
        ;; TAB auto-completion in term buffers
        (:after comint :map comint-mode-map
          "TAB" #'company-complete
          [tab] #'company-complete))

      (:when (featurep! :completion ivy)
        (:after ivy
          :map ivy-minibuffer-map
          "C-SPC" #'ivy-call-and-recenter  ; preview file
          "C-l"   #'ivy-alt-done
          "C-v"   #'yank)
        (:after counsel
          :map counsel-ag-map
          "C-SPC"    #'ivy-call-and-recenter ; preview
          "C-l"      #'ivy-done
          [C-return] #'+ivy/git-grep-other-window-action))

      (:when (featurep! :completion helm)
        (:after helm :map helm-map
          [remap next-line]     #'helm-next-line
          [remap previous-line] #'helm-previous-line
          [left]     #'left-char
          [right]    #'right-char
          "C-S-f"    #'helm-previous-page
          "C-S-n"    #'helm-next-source
          "C-S-p"    #'helm-previous-source
          (:when (featurep! :editor evil +everywhere)
            "C-j"    #'helm-next-line
            "C-k"    #'helm-previous-line
            "C-S-j"  #'helm-next-source
            "C-S-k"  #'helm-previous-source)
          "C-u"      #'helm-delete-minibuffer-contents
          "C-s"      #'helm-minibuffer-history
          ;; Swap TAB and C-z
          "TAB"      #'helm-execute-persistent-action
          [tab]      #'helm-execute-persistent-action
          "C-z"      #'helm-select-action)
        (:after helm-ag :map helm-ag-map
          "C--"      #'+helm-do-ag-decrease-context
          "C-="      #'+helm-do-ag-increase-context
          [left]     nil
          [right]    nil)
        (:after helm-files :map (helm-find-files-map helm-read-file-map)
          [C-return] #'helm-ff-run-switch-other-window
          "C-w"      #'helm-find-files-up-one-level)
        (:after helm-locate :map helm-generic-files-map
          [C-return] #'helm-ff-run-switch-other-window)
        (:after helm-buffers :map helm-buffer-map
          [C-return] #'helm-buffer-switch-other-window)
        (:after helm-occur :map helm-occur-map
          [C-return] #'helm-occur-run-goto-line-ow)
        (:after helm-grep :map helm-grep-map
          [C-return] #'helm-grep-run-other-window-action)))

;;; :ui
(map! (:when (featurep! :ui popup)
        :n "C-`"   #'+popup/toggle
        :n "C-~"   #'+popup/raise
        :g "C-x p" #'+popup/other)

      (:when (featurep! :ui workspaces)
        :n "C-t"   #'+workspace/new
        :n "C-S-t" #'+workspace/display
        :g "M-1"   #'+workspace/switch-to-0
        :g "M-2"   #'+workspace/switch-to-1
        :g "M-3"   #'+workspace/switch-to-2
        :g "M-4"   #'+workspace/switch-to-3
        :g "M-5"   #'+workspace/switch-to-4
        :g "M-6"   #'+workspace/switch-to-5
        :g "M-7"   #'+workspace/switch-to-6
        :g "M-8"   #'+workspace/switch-to-7
        :g "M-9"   #'+workspace/switch-to-8
        :g "M-0"   #'+workspace/switch-to-final
        (:when IS-MAC
          :g "s-t"   #'+workspace/new
          :g "s-T"   #'+workspace/display
          :n "s-1"   #'+workspace/switch-to-0
          :n "s-2"   #'+workspace/switch-to-1
          :n "s-3"   #'+workspace/switch-to-2
          :n "s-4"   #'+workspace/switch-to-3
          :n "s-5"   #'+workspace/switch-to-4
          :n "s-6"   #'+workspace/switch-to-5
          :n "s-7"   #'+workspace/switch-to-6
          :n "s-8"   #'+workspace/switch-to-7
          :n "s-9"   #'+workspace/switch-to-8
          :n "s-0"   #'+workspace/switch-to-final)))

;;; :editor
(map! (:when (featurep! :editor format)
        :n "gQ" #'+format:region)<commit_msg>Make C-` & C-~ available outside of normal mode<commit_after>;;; config/default/+bindings.el -*- lexical-binding: t; -*-

(when (featurep! :editor evil +everywhere)
  ;; NOTE SPC u replaces C-u as the universal argument.

  ;; Minibuffer
  (define-key! evil-ex-completion-map
    "C-a" #'evil-beginning-of-line
    "C-b" #'evil-backward-char
    "C-f" #'evil-forward-char
    "C-j" #'next-complete-history-element
    "C-k" #'previous-complete-history-element)

  (define-key! :keymaps +default-minibuffer-maps
    [escape] #'abort-recursive-edit
    "C-a"    #'move-beginning-of-line
    "C-r"    #'evil-paste-from-register
    "C-u"    #'evil-delete-back-to-indentation
    "C-v"    #'yank
    "C-w"    #'doom/delete-backward-word
    "C-z"    (λ! (ignore-errors (call-interactively #'undo))))

  (when (featurep! :editor evil +everywhere)
    (define-key! :keymaps +default-minibuffer-maps
      "C-f"    #'forward-word
      "C-b"    #'backward-word
      "M-f"    #'forward-char
      "M-b"    #'backward-char
      "C-j"    #'next-line
      "C-k"    #'previous-line
      "C-S-j"  #'scroll-up-command
      "C-S-k"  #'scroll-down-command)
    (define-key! read-expression-map
      "C-j" #'next-line-or-history-element
      "C-k" #'previous-line-or-history-element)))


;;
;;; Global keybindings

;; Smart tab, these will only work in GUI Emacs
(map! :i [tab] (general-predicate-dispatch nil ; fall back to nearest keymap
                 (and (featurep! :editor snippets)
                      (bound-and-true-p yas-minor-mode)
                      (yas-maybe-expand-abbrev-key-filter 'yas-expand))
                 #'yas-expand
                 (and (featurep! :completion company +tng)
                      (+company-has-completion-p))
                 #'+company/complete)
      :v [tab] (general-predicate-dispatch nil
                 (and (bound-and-true-p yas-minor-mode)
                      (or (eq evil-visual-selection 'line)
                          (not (memq (char-after) (list ?\( ?\[ ?\{ ?\} ?\] ?\))))))
                 #'yas-insert-snippet)

      ;; Smarter newlines
      :i [remap newline] #'newline-and-indent  ; auto-indent on newline
      :i "C-j"           #'+default/newline    ; default behavior

      (:after help :map help-mode-map
        :n "o"       #'link-hint-open-link)
      (:after helpful :map helpful-mode-map
        :n "o"       #'link-hint-open-link)
      (:after info :map Info-mode-map
        :n "o"       #'link-hint-open-link)
      (:after apropos :map apropos-mode-map
        :n "o"       #'link-hint-open-link
        :n "TAB"     #'forward-button
        :n [tab]     #'forward-button
        :n [backtab] #'backward-button)
      (:after view :map view-mode-map
        [escape]  #'View-quit-all)
      (:after man :map Man-mode-map
        :n "q"    #'kill-current-buffer)

      (:after (evil-org evil-easymotion)
        :map evil-org-mode-map
        :m "gsh" #'+org/goto-visible)

      (:when (featurep! :editor multiple-cursors)
        :prefix "gz"
        :nv "d" #'evil-mc-make-and-goto-next-match
        :nv "D" #'evil-mc-make-and-goto-prev-match
        :nv "j" #'evil-mc-make-cursor-move-next-line
        :nv "k" #'evil-mc-make-cursor-move-prev-line
        :nv "m" #'evil-mc-make-all-cursors
        :nv "n" #'evil-mc-make-and-goto-next-cursor
        :nv "N" #'evil-mc-make-and-goto-last-cursor
        :nv "p" #'evil-mc-make-and-goto-prev-cursor
        :nv "P" #'evil-mc-make-and-goto-first-cursor
        :nv "q" #'evil-mc-undo-all-cursors
        :nv "t" #'+multiple-cursors/evil-mc-toggle-cursors
        :nv "u" #'evil-mc-undo-last-added-cursor
        :nv "z" #'+multiple-cursors/evil-mc-make-cursor-here
        :v  "I" #'evil-mc-make-cursor-in-visual-selection-beg
        :v  "A" #'evil-mc-make-cursor-in-visual-selection-end)

      ;; misc
      :n "C-S-f"  #'toggle-frame-fullscreen
      :n "C-+"    #'doom/reset-font-size
      ;; Buffer-local font resizing
      :n "C-="    #'text-scale-increase
      :n "C--"    #'text-scale-decrease
      ;; Frame-local font resizing
      :n "M-C-="  #'doom/increase-font-size
      :n "M-C--"  #'doom/decrease-font-size)


;;
;;; Module keybinds

;;; :completion
(map! (:when (featurep! :completion company)
        :i "C-@"      #'+company/complete
        :i "C-SPC"    #'+company/complete
        (:after company
          (:map company-active-map
            "C-w"     nil  ; don't interfere with `evil-delete-backward-word'
            "C-n"     #'company-select-next
            "C-p"     #'company-select-previous
            "C-j"     #'company-select-next
            "C-k"     #'company-select-previous
            "C-h"     #'company-show-doc-buffer
            "C-u"     #'company-previous-page
            "C-d"     #'company-next-page
            "C-s"     #'company-filter-candidates
            "C-S-s"   (cond ((featurep! :completion helm) #'helm-company)
                            ((featurep! :completion ivy)  #'counsel-company))
            "C-SPC"   #'company-complete-common
            "TAB"     #'company-complete-common-or-cycle
            [tab]     #'company-complete-common-or-cycle
            [backtab] #'company-select-previous
            [f1]      nil)
          (:map company-search-map  ; applies to `company-filter-map' too
            "C-n"     #'company-select-next-or-abort
            "C-p"     #'company-select-previous-or-abort
            "C-j"     #'company-select-next-or-abort
            "C-k"     #'company-select-previous-or-abort
            "C-s"     (λ! (company-search-abort) (company-filter-candidates))
            [escape]  #'company-search-abort))
        ;; TAB auto-completion in term buffers
        (:after comint :map comint-mode-map
          "TAB" #'company-complete
          [tab] #'company-complete))

      (:when (featurep! :completion ivy)
        (:after ivy
          :map ivy-minibuffer-map
          "C-SPC" #'ivy-call-and-recenter  ; preview file
          "C-l"   #'ivy-alt-done
          "C-v"   #'yank)
        (:after counsel
          :map counsel-ag-map
          "C-SPC"    #'ivy-call-and-recenter ; preview
          "C-l"      #'ivy-done
          [C-return] #'+ivy/git-grep-other-window-action))

      (:when (featurep! :completion helm)
        (:after helm :map helm-map
          [remap next-line]     #'helm-next-line
          [remap previous-line] #'helm-previous-line
          [left]     #'left-char
          [right]    #'right-char
          "C-S-f"    #'helm-previous-page
          "C-S-n"    #'helm-next-source
          "C-S-p"    #'helm-previous-source
          (:when (featurep! :editor evil +everywhere)
            "C-j"    #'helm-next-line
            "C-k"    #'helm-previous-line
            "C-S-j"  #'helm-next-source
            "C-S-k"  #'helm-previous-source)
          "C-u"      #'helm-delete-minibuffer-contents
          "C-s"      #'helm-minibuffer-history
          ;; Swap TAB and C-z
          "TAB"      #'helm-execute-persistent-action
          [tab]      #'helm-execute-persistent-action
          "C-z"      #'helm-select-action)
        (:after helm-ag :map helm-ag-map
          "C--"      #'+helm-do-ag-decrease-context
          "C-="      #'+helm-do-ag-increase-context
          [left]     nil
          [right]    nil)
        (:after helm-files :map (helm-find-files-map helm-read-file-map)
          [C-return] #'helm-ff-run-switch-other-window
          "C-w"      #'helm-find-files-up-one-level)
        (:after helm-locate :map helm-generic-files-map
          [C-return] #'helm-ff-run-switch-other-window)
        (:after helm-buffers :map helm-buffer-map
          [C-return] #'helm-buffer-switch-other-window)
        (:after helm-occur :map helm-occur-map
          [C-return] #'helm-occur-run-goto-line-ow)
        (:after helm-grep :map helm-grep-map
          [C-return] #'helm-grep-run-other-window-action)))

;;; :ui
(map! (:when (featurep! :ui popup)
        "C-`"   #'+popup/toggle
        "C-~"   #'+popup/raise
        "C-x p" #'+popup/other)

      (:when (featurep! :ui workspaces)
        :n "C-t"   #'+workspace/new
        :n "C-S-t" #'+workspace/display
        :g "M-1"   #'+workspace/switch-to-0
        :g "M-2"   #'+workspace/switch-to-1
        :g "M-3"   #'+workspace/switch-to-2
        :g "M-4"   #'+workspace/switch-to-3
        :g "M-5"   #'+workspace/switch-to-4
        :g "M-6"   #'+workspace/switch-to-5
        :g "M-7"   #'+workspace/switch-to-6
        :g "M-8"   #'+workspace/switch-to-7
        :g "M-9"   #'+workspace/switch-to-8
        :g "M-0"   #'+workspace/switch-to-final
        (:when IS-MAC
          :g "s-t"   #'+workspace/new
          :g "s-T"   #'+workspace/display
          :n "s-1"   #'+workspace/switch-to-0
          :n "s-2"   #'+workspace/switch-to-1
          :n "s-3"   #'+workspace/switch-to-2
          :n "s-4"   #'+workspace/switch-to-3
          :n "s-5"   #'+workspace/switch-to-4
          :n "s-6"   #'+workspace/switch-to-5
          :n "s-7"   #'+workspace/switch-to-6
          :n "s-8"   #'+workspace/switch-to-7
          :n "s-9"   #'+workspace/switch-to-8
          :n "s-0"   #'+workspace/switch-to-final)))

;;; :editor
(map! (:when (featurep! :editor format)
        :n "gQ" #'+format:region)
{'fraction_non_alphanumeric': 0.1753854476602651, 'fraction_numerical': 0.004219637543954558, 'mean_word_length': 1.7549925484351714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6527389', 'n_tokens_mistral': 7049, 'n_tokens_neox': 6619, 'n_words': 1205}