Code Monkey home page Code Monkey logo

.emacs.d's Introduction

emacs.el

Boostrapping straight

Bootstrapping straight as per instructions on https://github.com/radian-software/straight.el

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name
        "straight/repos/straight.el/bootstrap.el"
        (or (bound-and-true-p straight-base-dir)
            user-emacs-directory)))
      (bootstrap-version 7))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)

Essentials

This section configures the essentials of emacs, which are options that are not mode-specific

package repositories and use-package

Disable compiliation warnings.

(setq native-comp-async-report-warnings-errors 'silent)

Disable warning buffer popup unless error.

(setq warning-minimum-level :error)

Load package, add prominent repositories, and update package data.

(require 'package)
(setq package-archives '(("elpa" . "https://elpa.gnu.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")
                         ("org" . "https://orgmode.org/elpa/")))
(package-initialize)
(unless package-archive-contents (package-refresh-contents))

Install use-package if necessary, load it, and set it to auto-install packages hereon.

(unless (package-installed-p 'use-package) (package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)

no-littering (loading early required)

Load no-littering, move auto-save files from current to ‘.emacs.d/var/auto-save/’.

(use-package no-littering
  :config
  (no-littering-theme-backups)
  (setq auto-save-file-name-transforms
        `((".*" ,(no-littering-expand-var-file-name "auto-save/") t))))

visual basics (no external packages required)

Maximize frames by default.

(add-to-list 'default-frame-alist '(fullscreen . maximized))

Empty startup screen and scratch buffer.

(setq inhibit-startup-screen t
      initial-scratch-message nil)

Remove top menu bar, right scroll bar, and top tool bar.

(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

Display column number.

(column-number-mode)

Enable parenthesis highlighting in programming modes.

(add-hook 'prog-mode-hook #'show-paren-mode)

Highlight current line.

(global-hl-line-mode)

behaviour basics (no external packages required)

Remember recently opened files, recent lines and minibuffer-history.

(recentf-mode)
(save-place-mode)
(savehist-mode)

Limit size of history to 256.

(setq history-length 256)

Ignore files generated by elpa and no-littering.

(add-to-list 'recentf-exclude (format "%s/\\.emacs\\.d/elpa/.*" (getenv "HOME")))
(add-to-list 'recentf-exclude
             (recentf-expand-file-name no-littering-var-directory))
(add-to-list 'recentf-exclude
             (recentf-expand-file-name no-littering-etc-directory))

Auto-delete trailing whitespaces before each save.

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Auto-add final newline before each save.

(setq require-final-newline t)

Auto-refresh files.

(global-auto-revert-mode)

Set default tab width to 2 (can be overwritten by other modes like julia-mode) and indent using spaces instead of tabs.

(setq-default tab-width 2
              indent-tabs-mode nil)

Use C-x <arrow> to change between buffers.

(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)

Overwrite selected text when typing text.

(delete-selection-mode 1)

Prefer Prefer vertical splits over horizontal ones, taken from https://github.com/jamescherti/minimal-emacs.d

(setq split-width-threshold 170
      split-height-threshold nil)

Confirm upon exiting emacs

(setq confirm-kill-emacs 'y-or-n-p)

dired (no external packages required)

Always use human readable sizes.

(setq dired-listing-switches "-alFh")

Auto-refresh dired.

(setq global-auto-revert-non-file-buffers t)

transparency

Toggle transparency

(set-frame-parameter nil 'alpha-background 85) ; For current frame
(add-to-list 'default-frame-alist '(alpha-background . 85)) ; For all new frames henceforth
(defun yr/toggle-window-transparency ()
  "Toggle frame's background transparency."
  (interactive)
  (let* ((desired-alpha 85)) (set-frame-parameter nil 'alpha-background (if (not (frame-parameter nil 'alpha-background)) desired-alpha))))

visual theme

Load dracula-theme in GUI.

(use-package dracula-theme
  :init
  (if (display-graphic-p)
    (load-theme 'dracula t)))

visual fonts

Todo(?): fonts

vertico

Load vertico for vertical minibuffer completion UI as per instructions on https://github.com/minad/vertico

(use-package vertico
  :init
  (vertico-mode)
  (setq vertico-count 3)  ;; Customize number of candidates shown
  )

marginalia

Load marginalia for minibuffer annotations as per instructions on https://github.com/minad/marginalia

(use-package marginalia
  ;; Bind `marginalia-cycle' locally in the minibuffer.  To make the binding
  ;; available in the *Completions* buffer, add it to `completion-list-mode-map'.
  :bind (:map minibuffer-local-map
         ("M-A" . marginalia-cycle))
  ;; The :init configuration is always executed (Not lazy!)
  :init
  ;; Must be in the :init section of use-package such that the mode gets
  ;; enabled right away. Note that this forces loading the package.
  (marginalia-mode))

which-key

Install and activate which-key as per instructions on https://github.com/justbur/emacs-which-key

(use-package which-key
  :init
  (which-key-mode)
  :config
  (setq which-key-separator ": ")) ;; change seperator to fix vertical spacing issues

corfu

Load corfu for autocomplete as per instructions on https://github.com/minad/corfu

(use-package corfu
  :custom
  (corfu-auto t)  ;; Enable showing autocompletion automatically
  (corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
  :init
  (global-corfu-mode))

cape

Load cape to use company backends for corfu as per instructions on https://github.com/minad/cape

(use-package cape
  ;; Bind dedicated completion commands
  ;; Alternative prefix keys: C-c p, M-p, M-+, ...
  :bind (("C-c p p" . completion-at-point) ;; capf
         ("C-c p t" . complete-tag)        ;; etags
         ("C-c p d" . cape-dabbrev)        ;; or dabbrev-completion
         ("C-c p h" . cape-history)
         ("C-c p f" . cape-file)
         ("C-c p k" . cape-keyword)
         ("C-c p s" . cape-symbol)
         ("C-c p a" . cape-abbrev)
         ("C-c p l" . cape-line)
         ("C-c p w" . cape-dict)
         ("C-c p \\" . cape-tex)
         ("C-c p _" . cape-tex)
         ("C-c p ^" . cape-tex)
         ("C-c p &" . cape-sgml)
         ("C-c p r" . cape-rfc1345))
  :init
  ;; Add `completion-at-point-functions', used by `completion-at-point'.
  ;; NOTE: The order matters!
  (add-to-list 'completion-at-point-functions #'cape-dabbrev)
  (add-to-list 'completion-at-point-functions #'cape-file)
  ;; (add-to-list 'completion-at-point-functions #'cape-elisp-block)
  ;;(add-to-list 'completion-at-point-functions #'cape-history)
  ;;(add-to-list 'completion-at-point-functions #'cape-keyword)
  ;;(add-to-list 'completion-at-point-functions #'cape-tex)
  ;;(add-to-list 'completion-at-point-functions #'cape-sgml)
  ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345)
  ;;(add-to-list 'completion-at-point-functions #'cape-abbrev)
  ;;(add-to-list 'completion-at-point-functions #'cape-dict)
  ;;(add-to-list 'completion-at-point-functions #'cape-symbol)
  ;;(add-to-list 'completion-at-point-functions #'cape-line)
)

orderless

Load orderless for completion with space-seperated components as per instructions on https://github.com/oantolin/orderless

(use-package orderless
  :init
  (setq completion-styles '(orderless basic)
        completion-category-overrides '((file (styles partial-completion)))))

prescient

Load prescient for better ordering of completions as per instructions on https://github.com/radian-software/prescient.el

(use-package prescient
  :after vertico)
(use-package vertico-prescient
  :after prescient
  :init
  (vertico-prescient-mode))
(use-package corfu-prescient
  :after prescient
  :init
  (corfu-prescient-mode))

consult

Load consult for various useful commands as per instructions on https://github.com/minad/consult

;; Example configuration for Consult
(use-package consult
  ;; Replace bindings. Lazily loaded due by `use-package'.
  :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 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-flycheck)              ;; Alternative: consult-flymake
         ("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)
         ("M-g I" . consult-imenu-multi)
         ;; M-s bindings in `search-map'
         ("M-s d" . consult-fd)                    ;; Alternative: consult-find
         ("M-s D" . 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

  ;; Enable automatic preview at point in the *Completions* buffer. This is
  ;; relevant when you use the default completion UI.
  :hook (completion-list-mode . consult-preview-at-point-mode)

  ;; The :init configuration is always executed (Not lazy)
  :init

  ;; Optionally configure the register formatting. This improves the register
  ;; preview for `consult-register', `consult-register-load',
  ;; `consult-register-store' and the Emacs built-ins.
  (setq register-preview-delay 0.5
        register-preview-function #'consult-register-format)

  ;; Optionally tweak the register preview window.
  ;; This adds thin lines, sorting and hides the mode line of the window.
  (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)

  ;; Configure other variables and modes in the :config section,
  ;; after lazily loading the package.
  :config

  ;; Optionally configure preview. The default value
  ;; is 'any, such that any key triggers the preview.
  ;; (setq consult-preview-key 'any)
  ;; (setq consult-preview-key "M-.")
  ;; (setq consult-preview-key '("S-<down>" "S-<up>"))
  ;; For some commands and buffer sources it is useful to configure the
  ;; :preview-key on a per-command basis using the `consult-customize' macro.
  (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 "M-."
   :preview-key '(:debounce 0.4 any))

  ;; Optionally configure the narrowing key.
  ;; Both < and C-+ work reasonably well.
  (setq consult-narrow-key "<") ;; "C-+"

  ;; Optionally make narrowing help available in the minibuffer.
  ;; You may want to use `embark-prefix-help-command' or which-key instead.
  ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help)

  ;; By default `consult-project-function' uses `project-root' from project.el.
  ;; Optionally configure a different project root function.
  ;;;; 1. project.el (the default)
  ;; (setq consult-project-function #'consult--default-project--function)
  ;;;; 2. vc.el (vc-root-dir)
  ;; (setq consult-project-function (lambda (_) (vc-root-dir)))
  ;;;; 3. locate-dominating-file
  ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git")))
  ;;;; 4. projectile.el (projectile-project-root)
  ;; (autoload 'projectile-project-root "projectile")
  ;; (setq consult-project-function (lambda (_) (projectile-project-root)))
  ;;;; 5. No project support
  ;; (setq consult-project-function nil)
)

embark

Load embark as per instructions on https://github.com/oantolin/embark

(use-package embark
  :ensure t
  :bind
  (("C-." . embark-act)         ;; pick some comfortable binding
   ("C-;" . embark-dwim)        ;; good alternative: M-.
   ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'

  :init
  ;; Optionally replace the key help with a completing-read interface
  (setq prefix-help-command #'embark-prefix-help-command)

  (defun embark-which-key-indicator ()
    "An embark indicator that displays keymaps using which-key.
The which-key help message will show the type and value of the
current target followed by an ellipsis if there are further
targets."
    (lambda (&optional keymap targets prefix)
      (if (null keymap)
          (which-key--hide-popup-ignore-command)
        (which-key--show-keymap
         (if (eq (plist-get (car targets) :type) 'embark-become)
             "Become"
           (format "Act on %s '%s'%s"
                   (plist-get (car targets) :type)
                   (embark--truncate-target (plist-get (car targets) :target))
                   (if (cdr targets) "" "")))
         (if prefix
             (pcase (lookup-key keymap prefix 'accept-default)
               ((and (pred keymapp) km) km)
               (_ (key-binding prefix 'accept-default)))
           keymap)
         nil nil t (lambda (binding)
                     (not (string-suffix-p "-argument" (cdr binding))))))))

  (setq embark-indicators
        '(embark-which-key-indicator
          embark-highlight-indicator
          embark-isearch-highlight-indicator))

  (defun embark-hide-which-key-indicator (fn &rest args)
    "Hide the which-key indicator immediately when using the completing-read prompter."
    (which-key--hide-popup-ignore-command)
    (let ((embark-indicators
           (remq #'embark-which-key-indicator embark-indicators)))
      (apply fn args)))

  (advice-add #'embark-completing-read-prompter
              :around #'embark-hide-which-key-indicator)

  :config
  ;; Hide the mode line of the Embark live/completions buffers
  (add-to-list 'display-buffer-alist
               '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
                 nil
                 (window-parameters (mode-line-format . none)))))

Load embark-consult as per instructions on https://github.com/oantolin/embark

(use-package embark-consult
  :ensure t ; only need to install it, embark loads it after consult if found
  :hook
  (embark-collect-mode . consult-preview-at-point-mode))

jinx (disabled)

Load jinx for spell-checking. Disabled because of too many false negatives in tex. See minad/jinx#25

(use-package jinx
  :hook (emacs-startup . global-jinx-mode)
  :after tex
  :bind ([remap ispell-word] . jinx-correct))

Use vertico grid display to fit more suggestions on screen.

(setq vertico-multiform-categories '((jinx grid) (vertico-grid-annotate . 36)))
(vertico-multiform-mode 1)

dashboard

Set up dashboard as per instructions on: https://github.com/emacs-dashboard/emacs-dashboard

(use-package dashboard
  :config
  (dashboard-setup-startup-hook)    ;; open dashboard on startup
  (setq dashboard-center-content t) ;; center dashboard
  (setq dashboard-startupify-list '(dashboard-insert-items)) ;; only show items in dashboard
  (setq dashboard-items '((bookmarks . 12)   ;; show 12 bookmarks
                          (recents  . 36)))) ;; show 36 recent files

doom-modeline

Set up doom-modeline as per instructions on https://github.com/seagle0128/doom-modeline

(use-package doom-modeline
  :init
  (doom-modeline-mode 1))

prism

Install prism as per instructions on https://github.com/alphapapa/prism.el

(use-package prism
  :after julia-mode
  :hook (julia-mode . prism-whitespace-mode)) ;; auto-activate in julia-mode

dired-subtree

Load dired-subtree and bind dired-subtree-toggle to tab as per intstructions on https://www.youtube.com/watch?v=vm-FvNdYFcc

(use-package dired-subtree
  :after dired
  :bind (:map dired-mode-map
              ("<tab>" . dired-subtree-toggle)
              ("<C-tab>" . dired-subtree-cycle)))

casual-dired

Load casual-dired and bind it to ‘?’ as per instructions on https://github.com/kickingvegas/casual-dired

(use-package casual-dired
  :after dired
  :bind (:map dired-mode-map
              ("?" . 'casual-dired-tmenu)))

casual-bookmarks

Load casual-bookmark and bind it to `?` as per instructions on https://github.com/kickingvegas/casual-suite

(use-package casual-bookmarks
  :bind (:map bookmark-mode-map ("?" . 'casual-bookmarks-tmenu)))

openwith

Load openwith to open certain files with external programs by default as per instructions on https://github.com/thisirs/openwith

(use-package openwith
  :config
  (setq openwith-associations
        (list
         (list (openwith-make-extension-regexp
                '("doc" "xls" "ppt" "odt" "ods" "odg" "odp"))
               "libreoffice"
               '(file))
         ))
  :init
  (openwith-mode 1))

buffer-move

Load and setup buffer-move as per instructions on https://github.com/lukhas/buffer-move

(use-package buffer-move
  :bind
  (("C-x C-<up>" . buf-move-up)
   ("C-x C-<down>" . buf-move-down)
   ("C-x C-<left>" . buf-move-left)
   ("C-x C-<right>" . buf-move-right)))

powerthesaurus

Load powerthesaurus for looking up synonyms, antonyms and related terms as per instructions on https://github.com/SavchenkoValeriy/emacs-powerthesaurus

(use-package powerthesaurus
  :commands powerthesaurus-transient) ;; defer loading after powerthesaurus-transient is called

go-translate

Load go-translate to translate between German and English (C-n / C-p to switch direction), as per instructions on https://github.com/lorniu/go-translate

(use-package go-translate
  :commands gts-do-translate  ;; defer loading until gts-do-translate is called
  :config
  (setq gt-langs '(en fr))
  (setq gt-default-translator (gt-translator :engines (gt-google-engine))))

Org

basic setup

Load org when opening .org files.

(defun my/org-copy-special ()
  "Copy the current region using `org-copy-special` and deactivate the mark."
  (interactive)
  (org-copy-special)
  (deactivate-mark))
(use-package org
  :mode
  ("\\.org\\'" . org-mode) ;; defer loading and auto-activate when .org file is opened
  :bind (:map org-mode-map
              ("C-c C-x M-w" . my/org-copy-special))
  :config
  (setq org-startup-indented t
        org-startup-truncated nil
        org-ellipsis ""
        org-src-tab-acts-natively t       ;; enable indentation in source blocks
        org-support-shift-select 'always  ;; allow shift select
        org-image-actual-width nil)       ;; allow rescaling of images

  (setq org-preview-latex-default-process 'dvisvgm)
  (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.1))
  (defun my/text-scale-adjust-latex-previews ()
    "Adjust the size of latex preview fragments when changing the buffer's text scale."
    (pcase major-mode
      ('latex-mode
       (dolist (ov (overlays-in (point-min) (point-max)))
         (if (eq (overlay-get ov 'category)
                 'preview-overlay)
             (my/text-scale--resize-fragment ov))))
      ('org-mode
       (dolist (ov (overlays-in (point-min) (point-max)))
         (if (eq (overlay-get ov 'org-overlay-type)
                 'org-latex-overlay)
             (my/text-scale--resize-fragment ov))))))

  (defun my/text-scale--resize-fragment (ov)
    (overlay-put
     ov 'display
     (cons 'image
           (plist-put
            (cdr (overlay-get ov 'display))
            :scale (+ 1.0 (* 0.3 text-scale-mode-amount))))))

  (add-hook 'text-scale-mode-hook #'my/text-scale-adjust-latex-previews))

org-modern

Load org-modern as per instructions on https://github.com/minad/org-modern

(use-package org-modern
  :after org                   ;; defer loading after org
  :hook
  (org-mode . org-modern-mode) ;; auto-activate in org-mode
)

org-present

Setting up org-present for basic presentations in org-files as per instructions on: https://systemcrafters.net/emacs-tips/presentations-with-org-present/

(use-package org-present
  :after org
  :config
  (define-key org-present-mode-keymap [right] nil) ;; undo binding right key
  (define-key org-present-mode-keymap [left] nil)  ;; undo binding left key
  (define-key org-present-mode-keymap (kbd "<next>") 'org-present-next)   ;; bind next slide to pageup
  (define-key org-present-mode-keymap (kbd "<prior>") 'org-present-prev)) ;; bind previous slide to pagedown

visual-fill-column

Load visual-fill-column to pad and center text (in org-present) as per instructions on https://systemcrafters.net/emacs-tips/presentations-with-org-present/

(use-package visual-fill-column
  :init
  ;; Configure fill width
  (setq visual-fill-column-width 120
        visual-fill-column-center-text t)

  (defun my/org-present-start ()
    ;; Center the presentation and wrap lines
    (visual-fill-column-mode 1)
    (visual-line-mode 1))

  (defun my/org-present-end ()
    ;; Stop centering the document
    (visual-fill-column-mode 0)
    (visual-line-mode 0))

  (add-hook 'org-present-mode-hook 'my/org-present-start)
  (add-hook 'org-present-mode-quit-hook 'my/org-present-end))

  ;; Register hooks with org-present
  ;; :hook
  ;; (org-present-mode-hook . my/org-present-start)
  ;; (org-present-mode-quit-hook . my/org-present-end))

Denote

Install denote.

(use-package denote
  :hook
  (dired-mode . denote-dired-mode)    ;; file highlighting in dired
  :config
  (setq denote-directory "~/notes/"))

Git

magit

Load magit.

(use-package magit
  :commands magit-status) ;; defer loading until magit-status is called

forge

Load forge

(use-package forge
  :after magit) ;; defer loading until magit is loaded
(setq auth-sources '("~/.authinfo.gpg"))

Shell

Bash and bash aliases

Use bash as default shell and use bash aliases.

(setq explicit-shell-file-name "/bin/bash"
      shell-file-name "bash"
      explicit-bash.exe-args '("--noediting" "--login" "-ic")
      shell-command-switch "-ic")
(setenv "SHELL" shell-file-name)

Latex

Basic setup

Load auctex, reftex, and flyspell when opening .tex files.

(use-package tex
  :ensure auctex
  :mode
  ("\\.tex\\'" . latex-mode)
  :hook
  (LaTeX-mode . reftex-mode)      ;; always load reftex
  (LaTeX-mode . turn-on-flyspell) ;; always load flyspell
  (LaTeX-mode . TeX-fold-mode)    ;; always enable folding
  :init
  (setq TeX-parse-self t ;; auto-parse tex file on load
        TeX-auto-save t  ;; auto-parse tex file on save
        TeX-master nil)  ;; always query for master file
  (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
  :config
  (setq TeX-view-program-selection '((output-pdf "PDF Tools"))
        TeX-view-program-list '(("PDF Tools" TeX-pdf-tools-sync-view))
        TeX-source-correlate-mode t
        TeX-source-correlate-start-server t)
  <<tex-custom-highlighting>>
  <<tex-custom-verbatim-environments>>
  <<tex-custom-spellcheck-blacklist-macros>>
  <<tex-custom-spellcheck-blacklist-environments>>
  <<tex-custom-query-labels>>
  <<tex-custom-folding>>
  )

Custom highlighting

Highlight \cref like \ref

(setq font-latex-match-reference-keywords
      '(("cref" "{")))

Custom verbatim enviroments

Register lstlisting as verbatim environment, ignore it for syntax highlighting

(eval-after-load 'latex '(add-to-list 'LaTeX-verbatim-environments "lstlisting"))

Custom spellcheck blacklist

Also ignore arguments of cref and input

(setq flyspell-tex-command-regexp
      "\\(\\(begin\\|end\\)[ \t]*{\\|\\(cite[a-z*]*\\|label\\|ref\\|cref\\|eqref\\|usepackage\\|documentclass\\|input\\)[ \t]*\\(\\[[^]]*\\]\\)?{[^{}]*\\)")

Ignore content of lstlisting

(put 'LaTeX-mode 'flyspell-mode-predicate 'auctex-mode-flyspell-skip-myenv)
(defun auctex-mode-flyspell-skip-myenv ()
  (save-excursion
    (widen)
    (let ((p (point))
          (count 0))
      (not (or (and (re-search-backward "\\\\begin{\\(tikzpicture\\|lstlisting\\|myenv3\\)}" nil t)
                    (> p (point))
                    (or (not (re-search-forward "^\\\\end{\\(tikzpicture\\|lstlisting\\|myenv3\\)}" nil t))
                        (< p (point))))
               (eq 1 (progn (while (re-search-backward "`" (line-beginning-position) t)
                              (setq count (1+ count)))
                            (- count (* 2 (/ count 2))))))))))
(add-hook 'LaTeX-mode-hook (lambda () (setq flyspell-generic-check-word-predicate
                                            'auctex-mode-flyspell-skip-myenv)))

Custom query labels

Auto-query for labels of certain environments

(setq reftex-label-alist
      '(("convention" ?d "con:" "~\\ref{%s}" t  ("convention" "con."))
        ("corollary" ?p "cor:" "~\\ref{%s}" t  ("corollary" "cor."))
        ("definition" ?d "def:" "~\\ref{%s}" t  ("definition" "def."))
        ("example" ?x "ex:" "~\\ref{%s}" t  ("example" "ex."))
        ("lemma" ?p "lem:" "~\\ref{%s}" t  ("lemma" "lem."))
        ("proposition" ?p "prop:" "~\\ref{%s}" t  ("proposition" "prop."))
        ("remark" ?x "rem:" "~\\ref{%s}" t  ("remark" "rem."))
        ("theorem" ?p "thm:" "~\\ref{%s}" t ("theorem" "thm."))))
(add-hook 'LaTeX-mode-hook
          (lambda ()
            (LaTeX-add-environments
             '("convention" LaTeX-env-label)
             '("corollary" LaTeX-env-label)
             '("definition" LaTeX-env-label)
             '("example" LaTeX-env-label)
             '("lemma" LaTeX-env-label)
             '("proposition" LaTeX-env-label)
             '("remark" LaTeX-env-label)
             '("theorem" LaTeX-env-label))
            (add-to-list 'LaTeX-label-alist '("convention" . "con:"))
            (add-to-list 'LaTeX-label-alist '("corollary" . "cor:"))
            (add-to-list 'LaTeX-label-alist '("definition" . "def:"))
            (add-to-list 'LaTeX-label-alist '("example" . "ex:"))
            (add-to-list 'LaTeX-label-alist '("lemma" . "lem:"))
            (add-to-list 'LaTeX-label-alist '("proposition" . "prop:"))
            (add-to-list 'LaTeX-label-alist '("remark" . "rem:"))
            (add-to-list 'LaTeX-label-alist '("theorem" . "thm:"))))

Custom folding

Enable folding and unfolding

(defun TeX-fold-all ()
  (interactive)
  (let ((env (read-from-minibuffer "Environment: ")))
    (save-excursion
      (goto-char (point-min))
      (while (search-forward (format "begin{%s}" env) nil t)
        (TeX-fold-env)))))
(defun TeX-unfold-all ()
  (interactive)
  (let ((env (read-from-minibuffer "Environment: ")))
    (save-excursion
      (goto-char (point-min))
      (while (search-forward (format "begin{%s}" env) nil t)
        (TeX-fold-clearout-item)))))

Custom reftex-goto-label

By default, `reftex-goto-label` does not `push-mark` at the point of departure, so you cannot jump back by using `C-u C-SPC`. This function fixes this issue

(defun my-reftex-goto-label ()
  "Wrapper around reftex-goto-label with jump back functionality."
  (interactive)
  (push-mark)
  (reftex-goto-label))

company-backends

Load various company latex backends via cape for corfu (for autocomplete)

(use-package company-math
  :after tex
  :init
  (defun math-setup-capf ()
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-math-symbols-latex))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-math-symbols-unicode))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-latex-commands)))
  :hook
  (LaTeX-mode . math-setup-capf))

(use-package company-reftex
  :after tex
  :init
  (defun reftex-setup-capf ()
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-reftex-labels))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-reftex-citations)))
  :hook
  (LaTeX-mode . reftex-setup-capf))

(use-package company-auctex
  :after tex
  :init
  (defun auctex-setup-capf ()
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-auctex-labels))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-auctex-bibs))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-auctex-macros))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-auctex-symbols))
    (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-auctex-environments)))
  :hook
  (LaTeX-mode . auctex-setup-capf))

pdf-tools

Load pdf-tools to view pdfs as per instructions on https://github.com/vedang/pdf-tools

(use-package pdf-tools
  :init
  (pdf-tools-install)
  (setq pdf-view-resize-factor 1.05)) ;; decrease resizing factor for better control

citar

Load citar to handle global bibliography in all.bib (exported from zotero) as per instructions on https://github.com/emacs-citar/citar

(use-package citar
  :after tex
  :custom
  (citar-bibliography '("~/all.bib")))

Latex input

Customizing latex input method as per instructions on https://www.emacswiki.org/emacs/TeXInputMethod

(with-temp-buffer
  (activate-input-method "TeX") ;; the input method has to be triggered for `quail-package-alist' to be non-nil
  (let ((quail-current-package (assoc "TeX" quail-package-alist)))
    (quail-define-rules ((append . t))
                        ("^\\alpha" ?ᵅ)
                        ("\\NN" ?ℕ)
                        ("\\ZZ" ?ℤ)
                        ("\\QQ" ?ℚ)
                        ("\\RR" ?ℝ)
                        ("\\CC" ?ℂ))))

C++

indentation

Disable tabs indentation and set offset to 2.

(setq-default c-default-style "linux"
              c-basic-offset 2)

singular

Turn on C++-mode for files ending in “.sing” and “.lib” for Singular.

(setq auto-mode-alist (cons '("\\.sing\\'" . c++-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.lib\\'" .  c++-mode) auto-mode-alist))

Julia

julia-mode

Load julia-mode as per instructions on https://github.com/JuliaEditorSupport/julia-emacs

(use-package julia-mode
  :mode "\\.jl\\'") ;; defer loading until and auto-activate when .jl files are opened

eglot-jl

Load eglot-js for language server support as per instructions on https://github.com/non-Jedi/eglot-jl

(use-package eglot-jl
  :after julia-mode            ;; defer loading until julia-mode is started
  :hook
  (julia-mode . eglot-ensure)  ;; auto-activate when julia-mode is started
  (julia-mode . eglot-jl-init)
  :init
  (setq eglot-connect-timeout nil)
  :config
  (setq eldoc-echo-area-use-multiline-p nil))

vterm

Install vterm as per instructions on https://github.com/akermu/emacs-libvterm

(use-package vterm
  :after julia-mode) ;; defer loading until julia-mode is started

julia-repl

Install julia-repl as per instructions on https://github.com/tpapp/julia-repl

(use-package julia-repl
  :after julia-mode                    ;; defer loading until julia-mode is started
  :hook (julia-mode . julia-repl-mode) ;; auto-activate when julia-mode is started
  :init
  (setq exec-path (append exec-path '("/home/ren/.juliaup/bin")))
  (add-to-list 'load-path "/home/ren/.juliaup/bin/julia")
  :config
  (julia-repl-set-terminal-backend 'vterm)) ;; use vterm (recommended)

Copilot and GPTel

Installing copilot as per the instructions on https://github.com/copilot-emacs/copilot.el

(use-package copilot
  :straight (:host github :repo "copilot-emacs/copilot.el" :files ("*.el"))
  :hook (julia-mode . copilot-mode)
  :config
  (setq copilot--base-dir "/home/ren/.emacs.d/straight/repos/copilot.el/")
  (define-key copilot-completion-map (kbd "C-<tab>") 'copilot-accept-completion)
  (setq copilot-indent-offset-warning-disable t)) ;; disables a warning that always arises in tex-mode

Installing GPTel as per instructions on https://github.com/karthink/gptel

(straight-use-package 'gptel)

Local variables for tangling this configuration

Declare local variables below as safe

(setq safe-local-variable-values
      '((eval add-hook 'after-save-hook
              (lambda nil
                (if
                    (y-or-n-p "Tangle?")
                    (org-babel-tangle)))
              nil t)
        (eval add-hook 'after-save-hook
              (lambda nil
                (if
                    (y-or-n-p "Reload?")
                    (load-file user-init-file)))
              nil t)))

;; Local Variables: ;; eval: (add-hook ‘after-save-hook (lambda ()(if (y-or-n-p “Reload?”)(load-file user-init-file))) nil t) ;; eval: (add-hook ‘after-save-hook (lambda ()(if (y-or-n-p “Tangle?”)(org-babel-tangle))) nil t) ;; End:

.emacs.d's People

Contributors

yueren avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.