Skip to content

Instantly share code, notes, and snippets.

@AyakoGFX
Last active November 14, 2025 19:11
Show Gist options
  • Select an option

  • Save AyakoGFX/d6516269f324b9bb8eab7660b820d593 to your computer and use it in GitHub Desktop.

Select an option

Save AyakoGFX/d6516269f324b9bb8eab7660b820d593 to your computer and use it in GitHub Desktop.
Single file Emacs config
(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("nongnu" . "https://elpa.nongnu.org/nongnu/")
("elpa-devel" . "https://elpa.gnu.org/devel/")
("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes '(manoj-dark))
'(package-selected-packages
'(compat consult denote denote-menu diredfl lsp-pwsh marginalia
orderless org-appear powershell vertico)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; font
(if (eq window-system 'w32)
(add-to-list 'default-frame-alist
'(font . "Consolas-20"))
(add-to-list 'default-frame-alist
'(font . "Monospace-20")))
(setq-default cursor-type 'bar) ;; Options: 'box, 'bar, 'hollow, 'hbar
(use-package powershell
:ensure t
:if (eq system-type 'windows-nt) ; Only load on Windows
:config
;; Change default compile command for powershell
(add-hook 'powershell-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(format "powershell.exe -NoLogo -NonInteractive -Command \"& '%s'\""
(buffer-file-name))))))
;; Configure shell based on OS
(cond
;; Windows: Use PowerShell with full path
((eq system-type 'windows-nt)
(setq explicit-shell-file-name "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
(setq explicit-powershell.exe-args '("-NoLogo" "-NoExit"))
(setq shell-file-name "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"))
;; Linux: Use bash (or your preferred shell)
((eq system-type 'gnu/linux)
(setq explicit-shell-file-name "/bin/bash")
(setq shell-file-name "/bin/bash"))
;; macOS: Use zsh or bash
((eq system-type 'darwin)
(setq explicit-shell-file-name "/bin/zsh")
(setq shell-file-name "/bin/zsh")))
;; Optional: Helper function to launch PowerShell on Windows
(when (eq system-type 'windows-nt)
(defun my/powershell-term ()
"Launch PowerShell in ansi-term"
(interactive)
(ansi-term "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" "powershell"))
(global-set-key (kbd "C-c p") 'my/powershell-term))
;; basic modes
;; (global-hl-line-mode 1)
(context-menu-mode 1)
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(global-visual-line-mode t)
(global-display-line-numbers-mode 1)
(save-place-mode 1)
(global-auto-revert-mode 1)
(horizontal-scroll-bar-mode -1)
(delete-selection-mode t) ;; overwrite selected text
(setq ring-bell-function 'ignore
make-backup-files nil
use-dialog-box nil
auto-save-default nil
create-lockfiles nil
inhibit-startup-message t
global-auto-revert-non-file-buffers t
ibuffer-expert t
column-number-mode t
initial-scratch-message "")
;; clipboard
(setq x-select-enable-clipboard t
save-interprogram-paste-before-kill t
yank-pop-change-selection t)
;; Short answers only please
(defalias 'yes-or-no-p 'y-or-n-p)
(setq-default use-short-answers t)
;; Disable tabs globally and set tab width
(setq-default indent-tabs-mode nil) ;; Use spaces instead of tabs
(setq-default tab-width 4) ;; Set tab width to 4 spaces
;; Converting Tabs and Spaces
;; Convert Tabs to Spaces: Use M-x untabify
;; Convert Spaces to Tabs: Use M-x tabify
;; Set UTF-8 encoding
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(fringe-mode 0)
;; Optional: disable startup screen and messages
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
;; start notes
;; do not format this
(setq denote-org-front-matter
"#+TITLE: %s
#+DATE: %s
#+FILETAGS: %s
#+IDENTIFIER: %s
\n")
(setq org-agenda-files (list "~/denote/org/agenda.org"))
(global-set-key (kbd "C-c a") 'org-agenda)
;; open org-agenda-files
(global-set-key (kbd "C-c o")
(lambda ()
(interactive)
(find-file (car org-agenda-files))))
;; migerate all org roam notes to denote
;; (load-file "~/.emacs.d/manual/nm-org-roam-to-denote.el")
(use-package denote
:ensure t)
;; Remember to check the doc strings of those variables.
(setq denote-directory (expand-file-name "~/denote/"))
(setq denote-known-keywords '("emacs" "philosophy" "politics" "economics"))
(setq denote-infer-keywords t)
(setq denote-sort-keywords t)
(setq denote-file-type nil) ; Org is the default, set others here
(setq denote-prompts '(subdirectory title keywords))
(setq denote-excluded-directories-regexp nil)
(setq denote-excluded-keywords-regexp nil)
(setq denote-rename-confirmations '(rewrite-front-matter modify-file-name))
(setq denote-save-buffer t)
;; Pick dates, where relevant, with Org's advanced interface:
(setq denote-date-prompt-use-org-read-date t)
(setq denote-date-format nil) ; read doc string
(setq denote-backlinks-show-context t)
(add-hook 'text-mode-hook #'denote-fontify-links-mode-maybe)
(add-hook 'dired-mode-hook #'denote-dired-mode-in-directories)
;; (add-hook 'dired-mode-hook #'denote-dired-mode) ;; on in dired
(denote-rename-buffer-mode 1)
(let ((map global-map))
(define-key map (kbd "C-c d n") #'denote)
(define-key map (kbd "C-c d c") #'denote-region) ; "contents" mnemonic
(define-key map (kbd "C-c d N") #'denote-type)
(define-key map (kbd "C-c d d") #'denote-date)
(define-key map (kbd "C-c d z") #'denote-signature) ; "zettelkasten" mnemonic
(define-key map (kbd "C-c d s") #'denote-subdirectory)
(define-key map (kbd "C-c d t") #'denote-template)
;; If you intend to use Denote with a variety of file types, it is
;; easier to bind the link-related commands to the `global-map', as
;; shown here. Otherwise follow the same pattern for `org-mode-map',
;; `markdown-mode-map', and/or `text-mode-map'.
(define-key map (kbd "C-c d i") 'denote-link-or-create) ; "insert" mnemonic
(define-key map (kbd "C-c d I") #'denote-add-links)
(define-key map (kbd "C-c d b") #'denote-backlinks)
(define-key map (kbd "C-c d f f") #'denote-find-link)
(define-key map (kbd "C-c d f b") #'denote-find-backlink)
;; Note that `denote-rename-file' can work from any context, not just
;; Dired bufffers. That is why we bind it here to the `global-map'.
(define-key map (kbd "C-c d r") #'denote-rename-file)
(define-key map (kbd "C-c d R") #'denote-rename-file-using-front-matter))
;; Key bindings specifically for Dired.
(let ((map dired-mode-map))
(define-key map (kbd "C-c C-d C-i") #'denote-link-dired-marked-notes)
(define-key map (kbd "C-c C-d C-r") #'denote-dired-rename-files)
(define-key map (kbd "C-c C-d C-k") #'denote-dired-rename-marked-files-with-keywords)
(define-key map (kbd "C-c C-d C-R") #'denote-dired-rename-marked-files-using-front-matter))
(with-eval-after-load 'org-capture
(setq denote-org-capture-specifiers "%l\n%i\n%?")
(add-to-list 'org-capture-templates
'("n" "New note (with denote.el)" plain
(file denote-last-path)
#'denote-org-capture
:no-save t
:immediate-finish nil
:kill-buffer t
:jump-to-captured t)))
;; Also check the commands `denote-link-after-creating',
;; `denote-link-or-create'. You may want to bind them to keys as well.
;; If you want to have Denote commands available via a right click
;; context menu, use the following and then enable
;; `context-menu-mode'.
(add-hook 'context-menu-functions #'denote-context-menu)
;; (use-package consult-denote
;; :ensure t)
;; (define-key global-map (kbd "C-c d f") #'consult-denote-find)
;; (define-key global-map (kbd "C-c d g") #'consult-denote-grep)
;; (consult-denote-mode 1)
(use-package denote-menu
:ensure t)
(setq denote-menu-title-column-width 60) ;; <-- default is 85
(setq denote-menu-date-column-width 17) ; Set to 17
(setq denote-menu-signature-column-width 10) ; Set to 10
(setq denote-menu-keywords-column-width 30) ; Set to 30
(global-set-key (kbd "C-c z") #'list-denotes)
(define-key denote-menu-mode-map (kbd "c") #'denote-menu-clear-filters)
(define-key denote-menu-mode-map (kbd "f") #'denote-menu-filter)
(define-key denote-menu-mode-map (kbd "k") #'denote-menu-filter-by-keyword)
(define-key denote-menu-mode-map (kbd "o") #'denote-menu-filter-out-keyword)
(define-key denote-menu-mode-map (kbd "e") #'denote-menu-export-to-dired)
(define-key denote-menu-mode-map (kbd "l") #'my-denote-list-all-keywords)
(define-key denote-menu-mode-map (kbd "s") #'denote-menu-filter-subdir)
(define-key global-map (kbd "C-c d l") #'my-denote-list-all-keywords)
(defun denote-menu-filter-subdir (subdir)
"Filter `denote-menu' entries to files within SUBDIR.
SUBDIR is chosen interactively relative to `denote-directory'."
(interactive
(list (read-directory-name "Choose subdirectory: " denote-directory)))
(let* ((absolute-subdir (expand-file-name subdir))
(matching-files (seq-filter
(lambda (file)
(string-prefix-p absolute-subdir (file-name-directory file)))
(denote-directory-files))))
(setq tabulated-list-entries
(lambda ()
(mapcar #'denote-menu--path-to-entry matching-files)))
(revert-buffer)))
;; list all the keywords = #+FILETAGS
(defun my-denote-list-all-keywords ()
"List all unique keywords used in Denote files recursively and show them in the message buffer."
(interactive)
(let* ((files (directory-files-recursively (denote-directory) "\\..*$"))
(all-keywords '()))
(dolist (file files)
(when-let ((keywords (denote-retrieve-filename-keywords file)))
(setq all-keywords
(append all-keywords
(mapcar (lambda (kw)
(split-string
(replace-regexp-in-string "_" " " kw)
" " t))
(split-string keywords "--" t))))))
(message "All keywords: %s"
(string-join
(delete-dups
(sort (cl-remove-duplicates (apply #'append all-keywords)
:test #'string-equal)
#'string-lessp))
", "))))
;; end of notes
(use-package compat
:ensure t)
(use-package vertico
:ensure t
:custom
(vertico-resize t) ;; Grow and shrink the Vertico minibuffer
:init
(vertico-mode))
;; vertico-buffer-mode
;; vertico-mouse-mode
;; vertico-flat-mode
;; vertico-reverse-mode
(use-package vertico-directory
:after vertico
:ensure nil
;; More convenient directory navigation commands
:bind (:map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
;; Tidy shadowed file names
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:ensure t
:init
(savehist-mode 1))
;; A few more useful configurations...
(use-package emacs
:ensure t
:custom
(enable-recursive-minibuffers t)
(read-extended-command-predicate #'command-completion-default-include-p)
:init
(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))
(setq read-file-name-completion-ignore-case t
read-buffer-completion-ignore-case t
completion-ignore-case t)
;; marginalia
(use-package marginalia
:ensure t
:config
(marginalia-mode 1))
;; orderless
(use-package orderless
:ensure t
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles partial-completion)))))
;; Colorful dired
(use-package diredfl
:ensure t)
;; (add-hook 'dired-mode-hook #'diredfl-mode)
(use-package dired
:ensure nil
:bind (:map dired-mode-map
("b" . dired-up-directory))
:config ; Guess a default target directory
(setq dired-mouse-drag-files t
dired-dwim-target t
dired-omit-verbose nil
delete-by-moving-to-trash t
dired-recursive-deletes 'always
dired-recursive-copies 'always
dired-hide-details-hide-symlink-targets nil
dired-kill-when-opening-new-dired-buffer t)
;; Show directory first
(setq dired-listing-switches "-alh --group-directories-first"))
;; Hide the details in dired
;; (add-hook 'dired-mode-hook #'denote-dired-mode)
(add-hook 'dired-mode-hook #'dired-hide-details-mode) ;; on in dired
(use-package dired-x
:demand t
:config
(let ((cmd (cond ((eq system-type 'darwin) "open") ;; macOS
((eq system-type 'gnu/linux) "xdg-open") ;; Linux
((eq system-type 'windows-nt) "start") ;; Windows
(t "")))) ;; Default to empty for unknown OS
(setq dired-guess-shell-alist-user
`(("\\.pdf\\'" ,cmd)
("\\.docx\\'" ,cmd)
("\\.\\(?:djvu\\|eps\\)\\'" ,cmd)
("\\.\\(?:jpg\\|jpeg\\|png\\|gif\\|xpm\\)\\'" ,cmd)
("\\.\\(?:xcf\\)\\'" ,cmd)
("\\.csv\\'" ,cmd)
("\\.tex\\'" ,cmd)
("\\.\\(?:mp4\\|mkv\\|avi\\|flv\\|rm\\|rmvb\\|ogv\\)\\(?:\\.part\\)?\\'" ,cmd)
("\\.\\(?:mp3\\|flac\\)\\'" ,cmd)
("\\.html?\\'" ,cmd)
("\\.md\\'" ,cmd)))))
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
(use-package consult
:ensure t
: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-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
:hook (completion-list-mode . consult-preview-at-point-mode)
:init
(setq register-preview-delay 0.5
register-preview-function #'consult-register-format)
(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)
:config
(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 '(:debounce 0.4 any))
;; (setq consult-find-args "fd --type f") ; Its value is (setq consult-find-args "find . -not ( -path */.[A-Za-z]* -prune )")
(setq consult-narrow-key "<")) ;; Close consult package
;; (global-set-key [mouse-9] #'next-buffer)
;; (global-set-key [mouse-8] #'previous-buffer)
(global-set-key (kbd "M-1") 'previous-buffer)
(global-set-key (kbd "M-2") 'next-buffer)
(global-set-key (kbd "C-;") 'comment-line)
(global-set-key (kbd "C-c r") 'rot13)
(global-set-key (kbd "C-c f") #'find-file-at-point)
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
;; (global-set-key (kbd "<f8>") 'save-buffer)
(global-set-key (kbd "<f8>") 'wsl-copy)
;; (global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-x C-b") 'persp-ibuffer)
(global-set-key (kbd "C-x C-k") (lambda () (interactive) (kill-buffer (current-buffer)))) ;; kill buff no asking
(global-set-key (kbd "C-c q") #'join-line)
(global-set-key (kbd "<f2>") #'rgrep)
(global-set-key (kbd "C-c j") #'replace-string)
;; Window manipulation (used with windmove, hence _Ctrl_-shift bindings)
(global-set-key (kbd "S-C-<right>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<left>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)
;; window
(global-set-key (kbd "M-o") 'other-window)
(global-set-key (kbd "M-0") 'delete-window)
(defun my/toggle-shell ()
;; "Toggle the `shell' buffer."
(interactive)
(if (get-buffer "*shell*")
(if (equal (current-buffer) (get-buffer "*shell*"))
(bury-buffer)
(pop-to-buffer "*shell*"))
(shell)))
(global-set-key (kbd "<f1>") #'my/toggle-shell)
(defun my/backward-kill-spaces-or-char-or-word ()
(interactive)
(cond
((looking-back (rx (char word)) 1)
(backward-kill-word 1))
((looking-back (rx (char blank)) 1)
(delete-horizontal-space t))
(t
(backward-delete-char 1))))
(global-set-key (kbd "<C-backspace>") 'my/backward-kill-spaces-or-char-or-word)
(with-eval-after-load 'org
(define-key org-mode-map (kbd "C-c d h") #'org-toggle-inline-images))
(use-package org-tempo
:ensure nil
:config
(add-to-list 'org-structure-template-alist '("sh" . "src sh"))
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
(add-to-list 'org-structure-template-alist '("li" . "src lisp"))
(add-to-list 'org-structure-template-alist '("sc" . "src scheme"))
(add-to-list 'org-structure-template-alist '("ts" . "src typescript"))
(add-to-list 'org-structure-template-alist '("py" . "src python"))
(add-to-list 'org-structure-template-alist '("go" . "src go"))
(add-to-list 'org-structure-template-alist '("yaml" . "src yaml"))
(add-to-list 'org-structure-template-alist '("json" . "src json")))
(use-package org-appear
:ensure t)
(add-hook 'org-mode-hook 'org-appear-mode)
(setq org-appear-autoemphasis t
org-appear-autolinks t
org-appear-autosubmarkers t
org-appear-autoentities t
org-appear-autokeywords t
org-appear-inside-latex t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment