From 9f672580bfcde6eba9a5f04a93f2ae326cbede6b Mon Sep 17 00:00:00 2001 From: Solomon Laing Date: Fri, 15 Sep 2023 11:23:55 +0930 Subject: [PATCH] basic emacs configuration, needs a lot of work, mostly stolen from dt --- .emacs.d/config.org | 398 +++++++++++++++++++++++++++++++ .emacs.d/early-init.el | 1 + .emacs.d/init.el | 4 + .emacs.d/scripts/elpaca-setup.el | 68 ++++++ 4 files changed, 471 insertions(+) create mode 100644 .emacs.d/config.org create mode 100644 .emacs.d/early-init.el create mode 100644 .emacs.d/init.el create mode 100644 .emacs.d/scripts/elpaca-setup.el diff --git a/.emacs.d/config.org b/.emacs.d/config.org new file mode 100644 index 0000000..80bd61f --- /dev/null +++ b/.emacs.d/config.org @@ -0,0 +1,398 @@ +#+TITLE: Ink's GNU Emacs Config +#+AUTHOR: Solomon Laing (Inkletblot) +#+DESCRIPTION: My personal Emacs config based that of Derek Taylor. +#+STARTUP: showeverything +#+OPTIONS: toc:2 + +* TABLE OF CONTENTS :toc: + +* IMPORTANT PROGRAMS TO LOAD FIRST +To keep with =config.org= a reasonable length, most of the config is in scripts +that are sourced here from the =~/.config/emacs/scripts/=. + +** Adding the scripts directory to path +#+begin_src emacs-lisp +(add-to-list 'load-path "~/.config/emacs/scripts/") +#+end_src + +** Sourcing the scripts +#+begin_src emacs-lisp +(require 'elpaca-setup) ;; the elpaca package manager +#+end_src + +* BACKUP +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 let's 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, to complete or to complete the common part. + +#+begin_src emacs-lisp +(use-package company + :defer 2 + :diminish + :custom + (company-begin-commands '(self-insert-command)) + (company-idle-delay .1) + (company-minimum-prefix-length 2) + (company-show-numbers t) + (company-tooltip-align-annotations 't) + (global-company-mode t)) + +(use-package company-box + :after company + :diminish + :hook (company-mode . company-box-mode)) +#+end_src + +* DIRED +#+begin_src emacs-lisp +(use-package dired-open + :config + (setq dired-open-extensions '(("gif" . "sxiv") + ("jpg" . "sxiv") + ("png" . "sxiv") + ("mkv" . "mpv") + ("mp4" . "mpv")))) + +(use-package peep-dired + :after dired + :hook (evil-normalize-keymaps . peep-dired-hook) + :config + (evil-define-key 'normal dired-mode-map (kbd "h") 'dired-up-directory) + (evil-define-key 'normal dired-mode-map (kbd "l") 'dired-open-file) ; use dired-find-file instead if not using dired-open package + (evil-define-key 'normal peep-dired-mode-map (kbd "j") 'peep-dired-next-file) + (evil-define-key 'normal peep-dired-mode-map (kbd "k") 'peep-dired-prev-file) +) + +#+end_src + +* EVIL +[[https://github.com/emacs-evil/evil][Evil]] is an extensible vi/vim layer for Emacs. Because...let's face it. The Vim keybindings are just plain better. + +#+begin_src emacs-lisp +;; Expands to: (elpaca evil (use-package evil :demand t)) +(use-package evil + :init ;; tweak evil's configuration before loading it + (setq evil-want-integration t ;; This is optional since it's already set to t by default. + evil-want-keybinding nil + evil-vsplit-window-right t + evil-split-window-below t + evil-undo-system 'undo-redo) ;; Adds vim-like C-r redo functionality + (evil-mode)) + +(use-package evil-collection + :after evil + :config + ;; 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) + +;; Using RETURN to follow links in Org/Evil +;; Unmap keys in 'evil-maps if not done, (setq org-return-follows-link t) will not work +(with-eval-after-load 'evil-maps + (define-key evil-motion-state-map (kbd "SPC") nil) + (define-key evil-motion-state-map (kbd "RET") nil) + (define-key evil-motion-state-map (kbd "TAB") nil)) +;; Setting RETURN key in org-mode to follow links + (setq org-return-follows-link t) + +#+end_src + +* FLYCHECK +Install =luacheck= from your Linux distro's 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 +(use-package flycheck + :ensure t + :defer t + :diminish + :init (global-flycheck-mode)) + +#+end_src + +** Zooming In/Out +You can use the bindings CTRL plus =/- for zooming in/out. You can also use CTRL plus the mouse wheel for zooming in/out. + +#+begin_src emacs-lisp +(global-set-key (kbd "C-=") 'text-scale-increase) +(global-set-key (kbd "C--") 'text-scale-decrease) +(global-set-key (kbd "") 'text-scale-increase) +(global-set-key (kbd "") 'text-scale-decrease) +#+end_src + +* GIT PROGRAMS +** Magit +[[https://magit.vc/manual/][Magit]] is a full-featured git client for Emacs. + +#+begin_src emacs-lisp +(use-package magit) + +#+end_src + +* HIGHLIGHT TODO +Adding highlights to TODO and related words. + +#+begin_src emacs-lisp +(use-package hl-todo + :hook ((org-mode . hl-todo-mode) + (prog-mode . hl-todo-mode)) + :config + (setq hl-todo-highlight-punctuation ":" + hl-todo-keyword-faces + `(("TODO" warning bold) + ("FIXME" error bold) + ("HACK" font-lock-constant-face bold) + ("REVIEW" font-lock-keyword-face bold) + ("NOTE" success bold) + ("DEPRECATED" font-lock-doc-face bold)))) + +#+end_src + +* IVY (COUNSEL) ++ Ivy, a generic completion mechanism for Emacs. ++ Counsel, a collection of Ivy-enhanced versions of common Emacs commands. ++ Ivy-rich allows us to add descriptions alongside the commands in M-x. + +#+begin_src emacs-lisp +(use-package counsel + :after ivy + :diminish + :config + (counsel-mode) + (setq ivy-initial-inputs-alist nil)) ;; removes starting ^ regex in M-x + +(use-package ivy + :bind + ;; ivy-resume resumes the last Ivy-based completion. + (("C-c C-r" . ivy-resume) + ("C-x B" . ivy-switch-buffer-other-window)) + :diminish + :custom + (setq ivy-use-virtual-buffers t) + (setq ivy-count-format "(%d/%d) ") + (setq enable-recursive-minibuffers t) + :config + (ivy-mode)) + +(use-package all-the-icons-ivy-rich + :ensure t + :init (all-the-icons-ivy-rich-mode 1)) + +(use-package ivy-rich + :after ivy + :ensure t + :init (ivy-rich-mode 1) ;; this gets us descriptions in M-x. + :custom + (ivy-virtual-abbreviate 'full + ivy-rich-switch-buffer-align-virtual-buffer t + ivy-rich-path-style 'abbrev) + :config + (ivy-set-display-transformer 'ivy-switch-buffer + 'ivy-rich-switch-buffer-transformer)) + +#+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. + +#+begin_src emacs-lisp +(use-package haskell-mode) +(use-package lua-mode) + +#+end_src + +* MINIBUFFER ESCAPE +By default, Emacs requires you to hit ESC three times to escape quit the minibuffer. + +#+begin_src emacs-lisp +(global-set-key [escape] 'keyboard-escape-quit) +#+end_src + +* MODELINE +The modeline is the bottom status bar that appears in Emacs windows. While you can create your own custom modeline, why go to the trouble when Doom Emacs already has a nice modeline package available. For more information on what is available to configure in the Doom modeline, check out: [[https://github.com/seagle0128/doom-modeline][Doom Modeline]] + +#+begin_src emacs-lisp +(use-package doom-modeline + :ensure t + :init (doom-modeline-mode 1) + :config + (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-persp-icon t)) ;; adds folder icon next to persp name + +#+end_src + +* NEOTREE +Neotree is a file tree viewer. When you open neotree, it jumps to the current file thanks to neo-smart-open. The neo-window-fixed-size setting makes the neotree width be adjustable. NeoTree provides following themes: classic, ascii, arrow, icons, and nerd. Theme can be config'd by setting "two" themes for neo-theme: one for the GUI and one for the terminal. I like to use 'SPC t' for 'toggle' keybindings, so I have used 'SPC t n' for toggle-neotree. + +| COMMAND | DESCRIPTION | KEYBINDING | +|----------------+---------------------------+------------| +| neotree-toggle | /Toggle neotree/ | SPC t n | +| neotree- dir | /Open directory in neotree/ | SPC d n | + +#+BEGIN_SRC emacs-lisp +(use-package neotree + :config + (setq neo-smart-open t + neo-show-hidden-files t + neo-window-width 55 + neo-window-fixed-size nil + inhibit-compacting-font-caches t + projectile-switch-project-action 'neotree-projectile-action) + ;; truncate long file names in neotree + (add-hook 'neo-after-create-hook + #'(lambda (_) + (with-current-buffer (get-buffer neo-buffer-name) + (setq truncate-lines t) + (setq word-wrap nil) + (make-local-variable 'auto-hscroll-mode) + (setq auto-hscroll-mode nil))))) + +#+end_src + +* ORG MODE +** Enabling Table of Contents +#+begin_src emacs-lisp +(use-package toc-org + :commands toc-org-enable + :init (add-hook 'org-mode-hook 'toc-org-enable)) +#+end_src + +** Enabling Org Bullets +Org-bullets gives us attractive bullets rather than asterisks. + +#+begin_src emacs-lisp +(add-hook 'org-mode-hook 'org-indent-mode) +(use-package org-bullets) +(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))) +#+end_src + +** Diminish Org Indent Mode +Removes "Ind" from showing in the modeline. + +#+begin_src emacs-lisp +(eval-after-load 'org-indent '(diminish 'org-indent-mode)) + +#+end_src + +** Org Level Headers +#+begin_src emacs-lisp + (custom-set-faces + '(org-level-1 ((t (:inherit outline-1 :height 1.7)))) + '(org-level-2 ((t (:inherit outline-2 :height 1.6)))) + '(org-level-3 ((t (:inherit outline-3 :height 1.5)))) + '(org-level-4 ((t (:inherit outline-4 :height 1.4)))) + '(org-level-5 ((t (:inherit outline-5 :height 1.3)))) + '(org-level-6 ((t (:inherit outline-5 :height 1.2)))) + '(org-level-7 ((t (:inherit outline-5 :height 1.1))))) +#+end_src + +** Source Code Block Tag Expansion +Org-tempo is not a separate package but a module within org that can be enabled. Org-tempo allows for ' from auto-pairing when electric-pair-mode is on. +;; Otherwise, org-tempo is broken when you try to