Spacemacs tangled user configuration
Table of Contents
- 1. Introduction
- 2. user-init
- 3. user-config
- 3.1. IDE config
- 3.1.1. Disable auto-indent in C/C++ mode after typing
::
- 3.1.2. MacOS
- 3.1.3. Prevent using UI dialogs for prompts
- 3.1.4. ccls
- 3.1.5. cmake-ide
- 3.1.6. company
- 3.1.7. lsp-ui
- 3.1.8. popup
- 3.1.9. dap
- 3.1.10. flycheck
- 3.1.11. Indentation for web development
- 3.1.12. groovy (Jenkinsfile)
- 3.1.13. plantuml
- 3.1.14. nvm
- 3.1.15. conf-mode
- 3.1.16. ROS
- 3.1.17. Style for linux kernel development
- 3.1.18. copilot
- 3.1.19. tramp + clang-format
- 3.1.20. Get current branch name in magit
- 3.1.1. Disable auto-indent in C/C++ mode after typing
- 3.2. Miscellaneous
- 3.2.1. No title bar
- 3.2.2. cursor
- 3.2.3. ripgrep
- 3.2.4.
C-a
for increasing number,C-x
for descreasing number - 3.2.5. Default python interpreter
- 3.2.6. Disable spacemacs buffer warnings
- 3.2.7. Find this file
- 3.2.8.
-
for going to the first non-blank position of the previous line - 3.2.9. helm-swoop
- 3.2.10. Keybinding for Zoom in / out
- 3.2.11. Kill frame when pressing
SPC q q
- 3.2.12. Make
w
in vim mode move to end of the word (not stopped by_
) - 3.2.13. Smooth scrolling
- 3.2.14. Transparency settings
- 3.2.15. Turn on xclip-mode
- 3.2.16. Use windows key as meta key
- 3.2.17. Visiting a file uses its truename as the visited-file name
- 3.2.18. Do not autosave undo history
- 3.2.19. Native compilation
- 3.3. org-mode
- 3.3.1. Export code blocks with current theme
- 3.3.2. org-ai
- 3.3.3. org-pomodora
- 3.3.4. org-agenda
- 3.3.5. org-cv
- 3.3.6. org-babel
- 3.3.7. org-journal
- 3.3.8. org-table
- 3.3.9. org-todo
- 3.3.10. org-hugo
- 3.3.11. org-roam
- 3.3.12. org-clock
- 3.3.13. Replace selected markdown region to org format
- 3.3.14. ob-lean4
- 3.3.15. ob-cmake
- 3.4. Utility
- 3.5. Workarounds
- 3.5.1. Workaround to suppress a yas related warning
- 3.5.2. Workaround for the bug where keybinding of the projectile-find-other-file is shadowed.
- 3.5.3. Workaround for the bug where fuzzy matching is not used in recent files
- 3.5.4. Workaround for the bug where company-mode and evil-mode are conflicting
- 3.5.5. Workaround for the bug where evil search breaks spacemacs.
- 3.5.6. Setting part of a word to be bold, italics, underline, and strikethrough.
- 3.5.7. Enable doom-modeline-icons in gui and disable them in terminal
- 3.1. IDE config
1. Introduction
This is a org file where its code snippets will be read by spacemacs
for user-init
and user-config
. It is inspired by spacemacs.org.
2. user-init
All code snippets under this section will be added to dotspacemacs//user-init
function, which is
Initialization function for user code.
It is called immediately after
dotspacemacs/init
, before layer configuration executes. This function is mostly useful for variables that need to be set before packages are loaded. If you are unsure, you should try in setting them in `dotspacemacs/user-config' first.
2.1. Locale
(setq system-time-locale "C")
2.2. Theme
(setq-default dotspacemacs-themes '( doom-monokai-pro spacemacs-dark doom-one doom-zenburn))
2.3. ROS
(defun spacemacs/update-ros-envs () "Update all environment variables in `spacemacs-ignored-environment-variables' from their values currently sourced in the shell environment (e.g. .bashrc)" (interactive) (setq exec-path-from-shell-check-startup-files nil) (exec-path-from-shell-copy-envs spacemacs-ignored-environment-variables) (message "ROS environment copied successfully from shell")) ;; Ignore any ROS environment variables since they might change depending ;; on which catkin workspace is used. When a new catkin workspace is chosen ;; call `spacemacs/update-ros-envs' to update theses envs accordingly (setq-default spacemacs-ignored-environment-variables '("ROS_IP" "PYTHONPATH" "CMAKE_PREFIX_PATH" "ROS_MASTER_URI" "ROS_PACKAGE_PATH" "ROSLISP_PACKAGE_DIRECTORIES" "PKG_CONFIG_PATH" "LD_LIBRARY_PATH"))
2.4. Shell
Set shell to be bash
explicitly because my default shell fish
does not work along with spacemacs.
(setq-default shell-file-name "/bin/bash")
2.5. Layers
2.5.1. groovy
(setq default-groovy-lsp-jar-path "~/.spacemacs.d/groovy-language-server-all.jar") (if (file-exists-p default-groovy-lsp-jar-path) (setq groovy-lsp-jar-path default-groovy-lsp-jar-path) (message (concat default-groovy-lsp-jar-path " does not exist")))
2.6. Workarounds
2.6.1. Workaround for unsigned packages
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
2.6.2. Acknowledge org-roam-v2
(setq org-roam-v2-ack t)
3. user-config
All code snippets under this section will be added to dotspacemacs//user-config
function, which is
Configuration function for user code.
This function is called at the very end of Spacemacs initialization after layers configuration. You are free to put any user code.
3.1. IDE config
3.1.1. Disable auto-indent in C/C++ mode after typing ::
;; Disable electric indentation in C and C++ modes (defun my-disable-electric-indent-mode () (setq-local c-electric-flag nil)) ;; Hook this function to C mode and C++ mode (add-hook 'c-mode-hook 'my-disable-electric-indent-mode) (add-hook 'c++-mode-hook 'my-disable-electric-indent-mode)
3.1.2. MacOS
; Use Command key as meta in emacs (setq mac-option-key-is-meta nil mac-command-key-is-meta t mac-command-modifier 'meta mac-option-modifier 'none)
3.1.3. Prevent using UI dialogs for prompts
(setq use-dialog-box nil)
3.1.4. ccls
(with-eval-after-load 'ccls (setq ccls-root-files (add-to-list 'ccls-root-files "build/compile_commands.json" t)) (setq ccls-sem-highlight-method 'font-lock) (setq ccls-initialization-options (list :cache (list :directory (file-truename (concat (file-name-as-directory spacemacs-cache-directory) ".ccls-cache"))) :compilationDatabaseDirectory "build")) ;; Only set the specific ccls path if it exists (when (file-exists-p "~/.spacemacs.d/ccls/Release/ccls") (setq ccls-executable (file-truename "~/.spacemacs.d/ccls/Release/ccls"))))
3.1.5. cmake-ide
;; C++ build dir setting (put 'cmake-ide-dir 'safe-local-variable 'stringp) (put 'cmake-ide-make-command 'safe-local-variable 'stringp) (put 'cmake-ide-cmake-args 'safe-local-variable 'stringp)
3.1.6. company
(with-eval-after-load 'company (define-key company-active-map (kbd "M-n") nil) (define-key company-active-map (kbd "M-p") nil) (define-key company-active-map (kbd "C-j") 'company-select-next) (define-key company-active-map (kbd "C-k") 'company-select-previous))
3.1.7. lsp-ui
(with-eval-after-load 'lsp-ui (define-key lsp-ui-peek-mode-map (kbd "C-j") 'lsp-ui-peek--select-next) (define-key lsp-ui-peek-mode-map (kbd "j") 'lsp-ui-peek--select-next) (define-key lsp-ui-peek-mode-map (kbd "C-k") 'lsp-ui-peek--select-prev) (define-key lsp-ui-peek-mode-map (kbd "k") 'lsp-ui-peek--select-prev))
3.1.8. popup
Use evil keybindings for selecting items in popup menus.
(with-eval-after-load 'popup (define-key popup-menu-keymap (kbd "C-j") 'popup-next) (define-key popup-menu-keymap (kbd "C-k") 'popup-previous))
3.1.9. dap
(add-hook 'dap-stopped-hook (lambda (arg) (call-interactively #'dap-hydra))) (add-hook 'dap-stopped-hook (lambda (arg) (call-interactively #'dap-hydra)))
3.1.10. flycheck
(with-eval-after-load 'flycheck (setq flycheck-check-syntax-automatically '(save idle-buffer-switch mode-enabled)))
3.1.11. Indentation for web development
(defun setup-web-dev-indent (n) ;; web development (setq coffee-tab-width n) ; coffeescript (setq javascript-indent-level n) ; javascript-mode (setq js-indent-level n) ; js-mode (setq js2-basic-offset n) ; js2-mode, in latest js2-mode, it's alias of js-indent-level (setq web-mode-markup-indent-offset n) ; web-mode, html tag in html file (setq web-mode-css-indent-offset n) ; web-mode, css in html file (setq web-mode-code-indent-offset n) ; web-mode, js code in html file (setq css-indent-offset n) ; css-mode ) (setup-web-dev-indent 2)
3.1.12. groovy (Jenkinsfile)
(setq groovy-indent-offset 2)
3.1.13. plantuml
(when (fboundp 'plantuml-mode) (require 'org-src) ;; Enable plantuml-mode for all *.pu files by default (add-to-list 'auto-mode-alist '("\\.pu\\'" . plantuml-mode)) (setq org-plantuml-jar-path plantuml-jar-path) (add-to-list 'org-src-lang-modes '("plantuml" . plantuml)) (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t))) )
3.1.14. nvm
;; TODO: use the default version instead of hard-coding the specific version (condition-case err (nvm-use "20") (error (message "Could not initialize nvm for emacs. %s" (error-message-string err))))
3.1.15. conf-mode
(add-to-list 'auto-mode-alist '("\\.eds\\'" . conf-mode)) (add-to-list 'auto-mode-alist '("\\.dcf\\'" . conf-mode))
3.1.16. ROS
3.1.16.1. helm-ros
;; ROS shortcut (spacemacs/set-leader-keys "ye" 'spacemacs/update-ros-envs) (spacemacs/declare-prefix "y" "ROS") (spacemacs/set-leader-keys "yy" 'helm-ros) (spacemacs/declare-prefix "yt" "ROS topics") (spacemacs/set-leader-keys "ytt" 'helm-ros-topics) (spacemacs/set-leader-keys "ytz" 'helm-ros-rostopic-hz) (spacemacs/set-leader-keys "yti" 'helm-ros-rostopic-info) (spacemacs/declare-prefix "yn" "ROS nodes") (spacemacs/set-leader-keys "yni" 'helm-ros-rosnode-info) (spacemacs/set-leader-keys "ynn" 'helm-ros-rosnode-list) (spacemacs/set-leader-keys "ynd" 'helm-ros-kill-node) (spacemacs/set-leader-keys "ynr" 'helm-ros-run-node) (spacemacs/set-leader-keys "ym" 'helm-ros-set-master-uri)
3.1.16.2. roslaunch-jump
;; TODO: load package lazily (use-package roslaunch-jump :defer 1 :load-path "~/.spacemacs.d/private/roslaunch-jump")
3.1.16.3. company-roslaunch
Autocompletion config for launch files.
;; TODO: load package lazily (use-package company-roslaunch :load-path "~/.spacemacs.d/private/company-roslaunch")
3.1.16.4. catkin-make
(use-package catkin-make :load-path "~/.spacemacs.d/private/catkin-make" :config (catkin-make-keybinding-setup))
3.1.17. Style for linux kernel development
;; Linux kernel development (defun c-lineup-arglist-tabs-only (ignored) "Line up argument lists by tabs, not spaces" (let* ((anchor (c-langelem-pos c-syntactic-element)) (column (c-langelem-2nd-pos c-syntactic-element)) (offset (- (1+ column) anchor)) (steps (floor offset c-basic-offset))) (* (max steps 1) c-basic-offset))) (add-hook 'c-mode-common-hook (lambda () ;; Add kernel style (c-add-style "linux-tabs-only" '("linux" (c-offsets-alist (arglist-cont-nonempty c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only)))))) (add-hook 'c-mode-hook (lambda () (let ((filename (buffer-file-name))) ;; Enable kernel mode for the appropriate files (when (and filename ;; TODO: avoid the harded coded path (string-match (expand-file-name "~/Dev/kernels") filename)) (setq indent-tabs-mode t) (setq show-trailing-whitespace t) (c-set-style "linux-tabs-only")))))
3.1.18. copilot
(setq copilot-node-executable (executable-find "node")) (with-eval-after-load 'company ;; disable inline previews (delq 'company-preview-if-just-one-frontend company-frontends)) ;; Keybindings (with-eval-after-load 'copilot (define-key copilot-completion-map (kbd "<tab>") 'copilot-accept-completion) (define-key copilot-completion-map (kbd "TAB") 'copilot-accept-completion) (define-key copilot-completion-map (kbd "C-TAB") 'copilot-accept-completion-by-word) (define-key copilot-completion-map (kbd "C-<tab>") 'copilot-accept-completion-by-word)) ;; Enable copilot mode in programming modes, markdown-mode and org-mode (add-hook 'prog-mode-hook 'copilot-mode) (add-hook 'markdown-mode-hook 'copilot-mode) (add-hook 'org-mode-hook 'copilot-mode) ;; Disable the warning message (add-hook 'copilot-mode-hook (lambda () (setq-local copilot--indent-warning-printed-p t)))
3.1.19. tramp + clang-format
clang-format does not work properly when editing a file on a remote host or in a docker container with tramp. See the issue here: https://github.com/kljohann/clang-format.el/issues/5
Here upon clang-format-region
call, we first check if the file is on a remote host or in a docker container.
- If not, we call
clang-format-region
as usual. - If yes, we first check if a file with the same path exists on the local disk.
- If yes, we assume it as the input file name for
clang-format-region
. - If not, we assume the input file is under the $HOME directory.
- If yes, we assume it as the input file name for
Depending on where the input file is assumed to be, clang-format
will find the .clang-format
file for
the formatting in a dominant parent directory of the assumed input file path.
(defun tramp-aware-clang-format (orig-fun start end &optional style assume-file-name) (unless assume-file-name (setq assume-file-name (if (file-remote-p buffer-file-name) (let ((maybe-existing-local-buffer-file-name (replace-regexp-in-string "/docker:[^:]+:" "" buffer-file-name))) ;; If file `maybe-existing-local-buffer-file-name' exists on local disk, use it. (if (file-exists-p maybe-existing-local-buffer-file-name) maybe-existing-local-buffer-file-name ;; Otherwise, use `buffer-file-name' as if it is under the $HOME directory. (concat (getenv "HOME") "/" (file-name-nondirectory buffer-file-name)))) buffer-file-name))) (message "assume-file-name: %s" assume-file-name) (apply orig-fun (list start end style assume-file-name))) (advice-add 'clang-format-region :around #'tramp-aware-clang-format)
3.1.20. Get current branch name in magit
(defun magit-add-current-branch-name-to-kill-ring () "Show the current branch in the echo-area and add it to the `kill-ring'." (interactive) (let ((branch (magit-get-current-branch))) (if branch (progn (kill-new branch) (message "%s" branch)) (user-error "There is not current branch")))) ; TODO: Move this keybinding from "Checkout" to "Do" section (with-eval-after-load 'magit (transient-insert-suffix 'magit-branch "b" '("k" "copy branch name" magit-add-current-branch-name-to-kill-ring)))
3.2. Miscellaneous
3.2.1. No title bar
(add-to-list 'default-frame-alist '(undecorated-round . t))
3.2.2. cursor
; Display Emacs cursor in terminal as it would be in GUI ;; (global-term-cursor-mode)
3.2.3. ripgrep
(custom-set-variables '(helm-ag-base-command "rg --no-heading") `(helm-ag-success-exit-status '(0 2)))
3.2.4. C-a
for increasing number, C-x
for descreasing number
(evil-define-key 'normal global-map (kbd "C-a") 'evil-numbers/inc-at-pt) (evil-define-key 'normal global-map (kbd "C-x") 'evil-numbers/dec-at-pt)
3.2.5. Default python interpreter
(setq python-shell-interpreter (executable-find "python3"))
3.2.6. Disable spacemacs buffer warnings
(setq spacemacs-buffer--warnings nil)
3.2.7. Find this file
Create binding to spacemacs.org file
(defun spacemacs/find-config-file () (interactive) (find-file (concat dotspacemacs-directory "/spacemacs.org"))) (spacemacs/set-leader-keys "fec" 'spacemacs/find-config-file)
3.2.8. -
for going to the first non-blank position of the previous line
(evil-define-key 'normal global-map (kbd "-") 'evil-previous-line-first-non-blank)
3.2.9. helm-swoop
(setq helm-swoop-use-fuzzy-match t) (setq helm-swoop-use-line-number-face t)
3.2.10. Keybinding for Zoom in / out
(define-key (current-global-map) (kbd "C-+") 'spacemacs/zoom-frm-in) (define-key (current-global-map) (kbd "C--") 'spacemacs/zoom-frm-out)
3.2.11. Kill frame when pressing SPC q q
The reason for this is that I mainly use emacs as a daemon and I don't want to close the daemon by accident.
(spacemacs/set-leader-keys "qq" 'spacemacs/frame-killer)
3.2.12. Make w
in vim mode move to end of the word (not stopped by _
)
(with-eval-after-load 'evil (defalias #'forward-evil-word #'forward-evil-symbol))
3.2.13. Smooth scrolling
;; Scroll one line at a time (less "jumpy" than defaults) (when (display-graphic-p) (setq mouse-wheel-scroll-amount '(1 ((shift) . 1)) mouse-wheel-progressive-speed nil)) (setq scroll-step 1 scroll-margin 0 scroll-conservatively 100000)
3.2.14. Transparency settings
(spacemacs/set-leader-keys "tt" 'spacemacs/toggle-transparency) (add-hook 'after-make-frame-functions 'spacemacs/enable-transparency)
3.2.15. Turn on xclip-mode
(use-package xclip :config (xclip-mode t))
3.2.16. Use windows key as meta key
It is meant to avoid conflicts with i3wm, where I use alt
as the meta key.
(setq x-super-keysym 'meta)
3.2.17. Visiting a file uses its truename as the visited-file name
E.g. when visiting a soft/hard link.
(setq find-file-visit-truename t)
3.2.18. Do not autosave undo history
(setq undo-tree-auto-save-history nil)
3.2.19. Native compilation
(when (and (fboundp 'native-comp-available-p) (native-comp-available-p)) (message "Native compilation is available") (setq native-comp-async-report-warnings-errors nil))
3.3. org-mode
3.3.1. Export code blocks with current theme
(defun my/org-inline-css-hook (exporter) "Insert custom inline css to automatically set the background of code to whatever theme I'm using's background" (when (eq exporter 'html) (let* ((my-pre-bg (face-background 'default)) (my-pre-fg (face-foreground 'default))) (setq org-html-head-extra (concat org-html-head-extra (format "<style type=\"text/css\">\n pre.src {background-color: %s; color: %s;}</style>\n" my-pre-bg my-pre-fg)))))) (add-hook 'org-export-before-processing-hook 'my/org-inline-css-hook)
3.3.2. org-ai
(use-package org-ai :ensure t :commands (org-ai-mode org-ai-global-mode) :custom (org-ai-openai-api-token (auth-source-pick-first-password :host "api.openai.com")) :init (add-hook 'org-mode-hook #'org-ai-mode) ; enable org-ai in org-mode (org-ai-global-mode) ; installs global keybindings on C-c M-a :config (setq org-ai-default-chat-model "gpt-4") ; if you are on the gpt-4 beta: (org-ai-install-yasnippets)) ; if you are using yasnippet and want `ai` snippets (require 'org-ai-talk)
3.3.3. org-pomodora
;; Lower the volume of the sounds (setq org-pomodoro-audio-player "play") (setq org-pomodoro-finished-sound-args "-v 0.01") (setq org-pomodoro-long-break-sound-args "-v 0.01") (setq org-pomodoro-short-break-sound-args "-v 0.01")
3.3.4. org-agenda
(defun scan-new-agenda-files () (interactive) (message "Scanning new agenda files...") (setq org-agenda-files (directory-files-recursively "~/org/" "\.org$" nil nil t))) (with-eval-after-load 'org-agenda (scan-new-agenda-files) (define-key org-agenda-mode-map "m" 'org-agenda-month-view) (define-key org-agenda-mode-map "y" 'org-agenda-year-view)) (spacemacs/set-leader-keys "aou" 'scan-new-agenda-files)
3.3.5. org-cv
(use-package ox-awesomecv :load-path "~/.spacemacs.d/private/org-cv" :init (require 'ox-awesomecv))
3.3.6. org-babel
(with-eval-after-load 'org (org-babel-do-load-languages 'org-babel-load-languages '((C . t) (python . t) (shell . t))))
3.3.7. org-journal
(with-eval-after-load 'org-journal (setq org-journal-dir "~/org/home/roam/journal/") (setq org-journal-file-type 'monthly) (setq org-journal-file-format "%Y%m%d.org")) (spacemacs/set-leader-keys "aojj" (lambda () (interactive) (org-journal-new-entry nil))) (spacemacs/declare-prefix "aojj" "journal-home")
3.3.8. org-table
(with-eval-after-load 'org-mode (define-key org-mode-map (kbd "C-<tab>") 'org-table-previous-field))
3.3.9. org-todo
(with-eval-after-load 'org (let ((capture-template "* TODO %?\n%U\n%i\n%a")) (progn (setq org-todo-keywords '((sequence "TODO(t)" "IN_PROGRESS" "UNDER_REVEW" "|" "DONE(d)") (sequence "REPORT(r)" "BUG(b)" "KNOWNCAUSE(k)" "|" "FIXED(f)") (sequence "|" "INACTIVE(i)" "INCOMPLETE(n)" "CANCELED(c)" "REPORTED(R)"))) (setq org-capture-templates '(("h" "Home" entry (file+headline "~/org/home/tasks.org" "Tasks") "* TODO %?\n%U\n%i\n%a") ("w" "Work" entry (file+headline "~/org/work/tasks.org" "Tasks") "* TODO %?\n%U\n%i\n%a"))) (setq org-project-capture-capture-template capture-template)))) (spacemacs/set-leader-keys "aoh" (lambda () (interactive) (find-file "~/org/home/tasks.org")) "aow" (lambda () (interactive) (find-file "~/org/work/tasks.org"))) (spacemacs/declare-prefix "aoh" "Home tasks") (spacemacs/declare-prefix "aow" "Work tasks")
3.3.10. org-hugo
(spacemacs/set-leader-keys-for-major-mode 'org-mode "Th" 'org-hugo-auto-export-mode)
3.3.11. org-roam
3.3.11.1. Automatically sync the database
(org-roam-db-autosync-mode)
3.3.11.2. Migrate the current buffer from org-roam v1 to v2
(defun org-roam-migrate-current-buffer-v1-to-v2 () (interactive) (org-roam-migrate-v1-to-v2))
3.3.12. org-clock
3.3.12.1. Save the clock history across Emacs sessions
(setq org-clock-persist 'history) (org-clock-persistence-insinuate)
3.3.13. Replace selected markdown region to org format
(defun replace-markdown-region-with-org (beginning end) "Replace the selected markdown region with its corresponding org-mode format." (interactive "r") (if (use-region-p) (let ((tmp-buffer "Markdown To Org Tmp")) (pcase (shell-command-on-region (region-beginning) (region-end) "pandoc -f markdown -t org" tmp-buffer t) (0 (message "Successfully converted to org-mode format.")) (127 (message "pandoc not found. Install it with 'sudo apt install pandoc'.")) (_ (message "Failed to convert the selected region to org-mode format.")) ) ) (message "No active region is found."))) (spacemacs/set-leader-keys-for-major-mode 'org-mode "RR" 'replace-markdown-region-with-org)
3.3.14. ob-lean4
(use-package ob-lean4 :load-path "~/.spacemacs.d/private/ob-lean4") (add-to-list 'org-babel-load-languages '(lean4 . t))
3.3.15. ob-cmake
(use-package ob-cmake :load-path "~/.spacemacs.d/private/ob-cmake") (add-to-list 'org-babel-load-languages '(cmake . t))
3.4. Utility
3.4.1. beacon mode
(beacon-mode 1)
3.4.2. Toggle clang-format on save
(defun c-c++-toggle-clang-format-on-save () (interactive) (cond (c-c++-enable-clang-format-on-save (message "[c-c++] disable clang-format on save") (setq c-c++-enable-clang-format-on-save nil)) ((not c-c++-enable-clang-format-on-save) (message "[c-c++] enable clang-format on save") (setq c-c++-enable-clang-format-on-save t)) )) (spacemacs/set-leader-keys-for-major-mode 'c-mode "Tf" 'c-c++-toggle-clang-format-on-save) (spacemacs/set-leader-keys-for-major-mode 'c++-mode "Tf" 'c-c++-toggle-clang-format-on-save) (spacemacs/declare-prefix-for-mode 'c-mode "Tf" "toggle-clang-format-on-save") (spacemacs/declare-prefix-for-mode 'c++-mode "Tf" "toggle-clang-format-on-save")
3.4.3. auto-indent
;; I want to disable pasting with formatting on C/C++ buffers (add-to-list 'spacemacs-indent-sensitive-modes 'c-mode) (add-to-list 'spacemacs-indent-sensitive-modes 'c++-mode)
3.4.4. format-all
(add-hook 'sh-mode-hook #'format-all-mode) (add-hook 'fish-mode-hook #'format-all-mode) (add-hook 'cmake-mode-hook #'format-all-mode)
3.4.5. glow, the markdown viewer
;; Configure glow viewer (defun start-glow-viewer () (interactive) (start-process "glow-markdown-viewer" nil "/usr/bin/x-terminal-emulator" (file-truename "~/.spacemacs.d/scripts/glow_mk_viewer.sh") (buffer-file-name nil)))
3.4.6. google-search
;; Set google as default search engine and open links with xdg-open or open depending on the OS (spacemacs/set-leader-keys "ag" 'engine/search-google) (setq browse-url-browser-function 'browse-url-generic engine/browser-function 'browse-url-generic browse-url-generic-program (cond ((string-equal system-type "darwin") "open") ((string-equal system-type "gnu/linux") "xdg-open")))
3.4.7. Kill all buffers
(defun nuke-all-buffers () (interactive) (mapcar 'kill-buffer (buffer-list)) (delete-other-windows)) (global-set-key (kbd "C-x K") 'nuke-all-buffers)
3.4.8. ranger
(with-eval-after-load 'ranger (define-key ranger-mode-map (kbd "M-h") 'ranger-prev-tab) (define-key ranger-mode-map (kbd "M-l") 'ranger-next-tab) (define-key ranger-mode-map (kbd "M-n") 'ranger-new-tab)) (spacemacs/set-leader-keys "ar" 'ranger)
3.4.9. cheat.sh
The one and only one cheatsheet.
(spacemacs/declare-prefix "aa" "cheat-sh") ;; Prompt to select a topic to show its cheatsheet (spacemacs/set-leader-keys "aaa" 'cheat-sh) ;; Show the help page of cheat.sh (spacemacs/set-leader-keys "aah" 'cheat-sh-help) ;; Get the cheatsheet for the marked region (spacemacs/set-leader-keys "aar" 'cheat-sh-region) ;; Get a random page of cheatsheet (spacemacs/set-leader-keys "aad" (lambda () (interactive) (cheat-sh ":random"))) (spacemacs/declare-prefix "aad" "cheat.sh/:random")
3.4.10. Disable persistent undo-tree
(require 'undo-tree) (setq undo-tree-auto-save-history nil)
3.4.11. chatgpt-shell
(use-package chatgpt-shell :load-path "~/.spacemacs.d/private/chatgpt-shell") (setq chatgpt-shell-openai-key (auth-source-pick-first-password :host "api.openai.com"))
3.5. Workarounds
3.5.1. Workaround to suppress a yas related warning
(defvaralias 'helm-c-yas-space-match-any-greedy 'helm-yas-space-match-any-greedy "Temporary alias for Emacs27")
3.5.2. Workaround for the bug where keybinding of the projectile-find-other-file is shadowed.
;; (with-eval-after-load 'lsp-mode (define-key lsp-command-map-prefix "ga" 'projectile-find-other-file))
3.5.3. Workaround for the bug where fuzzy matching is not used in recent files
(setq completion-styles `(basic partial-completion emacs22 initials ,(if (version<= emacs-version "27.0") 'helm-flex 'flex)))
3.5.4. Workaround for the bug where company-mode and evil-mode are conflicting
(evil-declare-change-repeat 'company-complete)
3.5.5. Workaround for the bug where evil search breaks spacemacs.
(defun kill-minibuffer () (interactive) (when (windowp (active-minibuffer-window)) (evil-ex-search-exit))) (add-hook 'mouse-leave-buffer-hook #'kill-minibuffer)
3.5.6. Setting part of a word to be bold, italics, underline, and strikethrough.
The visualization in org-mode can be wrong, which needs a fix.
;; This commented out because it messed up with org highlight ;; (setcar org-emphasis-regexp-components " \t('\"{[:alpha:]") ;; (setcar (nthcdr 1 org-emphasis-regexp-components) "[:alpha:]- \t.,:!?;'\")}\\") ;; (org-set-emph-re 'org-emphasis-regexp-components org-emphasis-regexp-components)
3.5.7. Enable doom-modeline-icons in gui and disable them in terminal
;; Enable doom-modeline-icons in gui and disable them in terminal ;; TODO: check if this is still working (defun enable-doom-modeline-icons() (setq doom-modeline-icon (display-graphic-p))) (defun enable-doom-modeline-icons-weird (_frame) ;; TODO: Don't know why this "not" is needed... (setq doom-modeline-icon (not (display-graphic-p)))) (add-hook 'focus-in-hook #'enable-doom-modeline-icons) (add-hook 'after-make-frame-functions #'enable-doom-modeline-icons-weird)