Emacs level up

This commit is contained in:
Aleksandr Lebedev 2025-01-30 12:42:20 +01:00
parent b2c1e8732b
commit e459041e92
2 changed files with 142 additions and 84 deletions

View file

@ -11,17 +11,16 @@
- [[#startup-time][Startup Time]]
- [[#app-launcher][App Launcher]]
- [[#standalone-run][Standalone run]]
- [[#backup-files-tilda-files][Backup files (tilda files)]]
- [[#company][Company]]
- [[#dashboard][Dashboard]]
- [[#diminish][Diminish]]
- [[#dired-file-manager][DIRED (File manager)]]
- [[#ediff][EDIFF]]
- [[#flycheck][FLYCHECK]]
- [[#fonts][Fonts]]
- [[#zooming-inout][Zooming In/Out]]
- [[#graphical-user-interface-tweaks][GRAPHICAL USER INTERFACE TWEAKS]]
- [[#disable-menubar-toolbars-and-scrollbars][Disable Menubar, Toolbars and Scrollbars]]
- [[#display-line-numbers-and-truncated-lines][Display Line Numbers and Truncated Lines]]
- [[#disable-gui-elements][Disable GUI elements]]
- [[#sane-defaults][Sane defaults]]
- [[#battery-info][Battery info]]
- [[#magit][MAGIT]]
- [[#minibuffer-escape][Minibuffer escape]]
@ -32,7 +31,6 @@
- [[#org-mode][ORG MODE]]
- [[#enabling-table-of-contents][Enabling Table of Contents]]
- [[#enabling-org-bullets][Enabling Org Bullets]]
- [[#disable-electric-indent][Disable Electric Indent]]
- [[#org-level-headers][Org Level Headers]]
- [[#source-code-block-tag-expansion][Source Code Block Tag Expansion]]
- [[#org-roam][ORG ROAM]]
@ -47,13 +45,18 @@
- [[#vterm][Vterm]]
- [[#vterm-toggle][Vterm-Toggle]]
- [[#sudo-edit][SUDO EDIT]]
- [[#language-support][Language support]]
- [[#nix][Nix]]
- [[#nerd-icons][Nerd Icons]]
- [[#nerd-icons-completion][Nerd Icons Completion]]
- [[#buffer-move][Buffer Move]]
- [[#vertico][Vertico]]
- [[#consult][Consult]]
- [[#embark][Embark]]
- [[#descriptions][Descriptions]]
- [[#theme][Theme]]
- [[#theme-loading][Theme loading]]
- [[#tldr][TLDR]]
- [[#transparency][Transparency]]
- [[#which-key][WHICH-KEY]]
@ -67,12 +70,17 @@
(setq evil-want-keybinding nil)
(setq evil-vsplit-window-right t)
(setq evil-split-window-below t)
(setq evil-undo-system 'undo-redo) ;; Adds vim-like C-r redo functionality
(evil-mode))
(use-package evil-collection
:ensure t
:after evil
:config
(setq evil-collection-mode-list '(dashboard dired ibuffer))
;; Do not uncomment this unless you want to specify each and every mode
;; that evil-collection should works with. The following line is here
;; for documentation purposes in case you need it.
;; (setq evil-collection-mode-list '(calendar dashboard dired ediff info magit ibuffer))
(add-to-list 'evil-collection-mode-list 'help) ;; evilify help mode
(evil-collection-init))
(use-package evil-tutor
:ensure t)
@ -107,6 +115,7 @@
(kylekrein/leader-keys
"." '(find-file :wk "Find file")
"f r" '(recentf-open :wk "Open recent file")
"f d" '(find-grep-dired :wk "Search for string in files in DIR")
"TAB TAB" '(comment-line :wk "Comment lines"))
(kylekrein/leader-keys
"b" '(:ignore t :wk "buffer")
@ -118,13 +127,14 @@
"b r" '(revert-buffer :wk "Reload buffer"))
(kylekrein/leader-keys
"e" '(:ignore t :wk "Eshell/Evaluate")
"e" '(:ignore t :wk "Eshell/Ediff/Evaluate")
"e b" '(eval-buffer :wk "Evaluate elisp in buffer")
"e d" '(eval-defun :wk "Evaluate defun containing or after point")
"e e" '(eval-expression :wk "Evaluate and elisp expression")
"e l" '(eval-last-sexp :wk "Evaluate elisp expression before point")
"e r" '(eval-region :wk "Evaluate elisp in region")
"e s" '(eshell :which-key "Eshell"))
"e s" '(eshell :which-key "Eshell")
"e f" '(ediff-files :wk "Run ediff on a pair of files"))
(kylekrein/leader-keys
"h" '(:ignore t :wk "Help")
@ -376,6 +386,11 @@ To use it, create a global keyboard shortcut with the following code
(app-launcher-run-app)
(delete-frame))))
#+end_src
* Backup files (tilda files)
By default, Emacs creates automatic backups of files in their original directories, such “file.el” and the backup “file.el~”. This leads to a lot of clutter, so lets tell Emacs to put all backups that it creates in the ~TRASH~ directory.
#+begin_src emacs-lisp
(setq backup-directory-alist '((".*" . "~/.local/share/Trash/files")))
#+end_src
* Company
[[https://company-mode.github.io/][Company]] is a text completion framework for Emacs. The name stands for “complete anything”. Completion will start automatically after you type a few letters. Use M-n and M-p to select, <return> to complete or <tab> to complete the common part.
#+begin_src emacs-lisp
@ -450,6 +465,19 @@ This package implements hiding or abbreviation of the modeline displays (lighter
;;(add-hook 'peep-dired-hook 'evil-normalize-keymaps)
#+end_src
* EDIFF
ediff is a diff program that is built into Emacs. By default, ediff splits files vertically and places the help frame in its own window. I have changed this so the two files are split horizontally and the help frame appears as a lower split within the existing window. Also, I create my own dt-ediff-hook where I add j/k for moving to next/prev diffs. By default, this is set to n/p.
#+begin_src emacs-lisp
(setq ediff-split-window-function 'split-window-horizontally
ediff-window-setup-function 'ediff-setup-windows-plain)
(defun dt-ediff-hook ()
(ediff-setup-keymap)
(define-key ediff-mode-map "j" 'ediff-next-difference)
(define-key ediff-mode-map "k" 'ediff-previous-difference))
(add-hook 'ediff-mode-hook 'dt-ediff-hook)
#+end_src
* FLYCHECK
Install luacheck from your Linux distros repositories for flycheck to work correctly with lua files. Install python-pylint for flycheck to work with python files. Haskell works with flycheck as long as haskell-ghc or haskell-stack-ghc is installed. For more information on language support for flycheck, [[https://www.flycheck.org/en/latest/languages.html][read this]].
#+begin_src emacs-lisp
@ -502,23 +530,25 @@ You can use the bindings CTRL plus =/- for zooming in/out. You can also use CTR
#+end_src
* GRAPHICAL USER INTERFACE TWEAKS
Let's make GNU Emacs look a little better.
** Disable Menubar, Toolbars and Scrollbars
#+begin_src emacs-lisp
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
#+end_src
** Display Line Numbers and Truncated Lines
#+begin_src emacs-lisp
(global-display-line-numbers-mode 1)
(global-visual-line-mode t)
#+end_src
** Disable GUI elements
* Sane defaults
The following settings are simple modes that are enabled (or disabled) so that Emacs functions more like you would expect a proper editor/IDE to function.
#+begin_src emacs-lisp
(delete-selection-mode 1) ;; You can select text and delete it by typing.
(electric-indent-mode -1) ;; Turn off the weird indenting that Emacs does by default.
(electric-pair-mode 1) ;; Turns on automatic parens pairing
;; The following prevents <> from auto-pairing when electric-pair-mode is on.
;; Otherwise, org-tempo is broken when you try to <s TAB...
(add-hook 'org-mode-hook (lambda ()
(setq-local electric-pair-inhibit-predicate
`(lambda (c)
(if (char-equal c ?<) t (,electric-pair-inhibit-predicate c))))))
(global-auto-revert-mode t) ;; Automatically show changes if the file has changed
(global-display-line-numbers-mode 1) ;; Display line numbers
(global-visual-line-mode t) ;; Enable truncated lines
(menu-bar-mode -1) ;; Disable the menu bar
(scroll-bar-mode -1) ;; Disable the scroll bar
(tool-bar-mode -1) ;; Disable the tool bar
(setq org-edit-src-content-indentation 0) ;; Set src block automatic indent to 0 instead of 2.
(setq use-file-dialog nil) ;; No file dialog
(setq use-dialog-box nil) ;; No dialog box
(setq pop-up-windows nil) ;; No popup windows
@ -550,6 +580,7 @@ The modeline is the bottom status bar that appears in Emacs windows. While you
(setq doom-modeline-height 35 ;; sets modeline height
doom-modeline-bar-width 5 ;; sets right bar width
doom-modeline-persp-name t ;; adds perspective name to modeline
doom-modeline-time t ;; shows time
doom-modeline-persp-icon t)) ;; adds folder icon next to persp name
#+end_src
* PROJECTILE
@ -607,14 +638,6 @@ Org-bullets gives us attractive bullets rather than asterisks.
(use-package org-bullets :ensure t)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
#+end_src
** Disable Electric Indent
Org mode source blocks have some really weird and annoying default indentation behavior. I think this has to do with electric-indent-mode, which is turned on by default in Emacs. So let's turn it OFF!
#+begin_src emacs-lisp
(electric-indent-mode -1)
(setq org-edit-src-content-indentation 0)
#+end_src
** Org Level Headers
#+begin_src emacs-lisp
(custom-set-faces
@ -805,6 +828,23 @@ Vterm is a terminal emulator within Emacs. The 'shell-file-name' setting sets t
"fu" '(sudo-edit-find-file :wk "Sudo find file")
"fU" '(sudo-edit :wk "Sudo edit file")))
#+end_src
* Language support
Emacs has built-in programming language modes for Lisp, Scheme, DSSSL, Ada, ASM, AWK, C, C++, Fortran, Icon, IDL (CORBA), IDLWAVE, Java, Javascript, M4, Makefiles, Metafont, Modula2, Object Pascal, Objective-C, Octave, Pascal, Perl, Pike, PostScript, Prolog, Python, Ruby, Simula, SQL, Tcl, Verilog, and VHDL. Other languages will require you to install additional modes.
** Nix
#+begin_src emacs-lisp
(use-package nix-mode
:ensure t
:mode ("\\.nix\\'" "\\.nix.in\\'"))
(use-package nix-drv-mode
:ensure nix-mode
:mode "\\.drv\\'")
(use-package nix-shell
:ensure nix-mode
:commands (nix-shell-unpack nix-shell-configure nix-shell-build))
(use-package nix-repl
:ensure nix-mode
:commands (nix-repl))
#+end_src
* Nerd Icons
#+begin_src emacs-lisp
(use-package nerd-icons
@ -909,14 +949,19 @@ one, an error is signaled."
;; (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'
(vertico-cycle t) ;; Enable cycling for `vertico-next/previous'
:bind (:map vertico-map
("C-j" . vertico-next)
("C-k" . vertico-previous)
:map minibuffer-local-map
("C-h" . backward-kill-word)
)
:init
(vertico-mode))
(vertico-mode t) ;; enable vertico for all buffers
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:ensure -1 ;;package is unavailable in nix
:init
(savehist-mode))
@ -957,6 +1002,13 @@ one, an error is signaled."
(completion-category-defaults nil)
(completion-category-overrides '((file (styles partial-completion)))))
#+end_src
** Consult
A collection of commands (like Counsel for Ivy), which provide additional completions.
#+begin_src emacs-lisp
#+end_src
** Embark
Provides actions for the current selection in Vertico completion list (ex. Remove/Rename file in ~find-file~)
** Descriptions
*** Marginalia
[[https://github.com/minad/marginalia/]]
@ -1001,6 +1053,11 @@ Descriptions for completions
;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config))
#+end_src
* TLDR
Too long didn't read - documentation
#+begin_src emacs-lisp
(use-package tldr :ensure t)
#+end_src
* Transparency
With Emacs version 29, true transparency has been added.
#+begin_src emacs-lisp

View file

@ -55,6 +55,7 @@
with pkgs; [
#nerd-fonts.jetbrains-mono
#jetbrains-mono
unzip
];
# Optionally override derivations.