Skip to content

I will keep my emacs configuration file up to date here - feel free to use!

Notifications You must be signed in to change notification settings

ylivuoto/emacs-conf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Emacs configuration

All the sections below will contain declarations for my emacs setup. When using .org configuration file, please include a short line in your .emacs or init.el file

;; Include something like this your initalization file:
  (org-babel-load-file (expand-file-name "~/.emacs.d/config/config.org"))

That is to include your fresh config file! Also, be careful when making changes. Sometimes, when making changes to settings graphically via M-x customize, emacs will create some new lines to .emacs file and there will be duplicates with the .org config file - watch out those! These customizations are possible to move separate custom.el file.

Well, your .emacs or init.el file and the config.org might look something like the contents in following sections.

Important

There are things that are not configured properly, like tabbing works differently in different modes etc. You may wish also customize vertico, consult, orderless and other packages for you. If you wish to have consistent setup, please check and set keybindings.

This configuration uses init.el file, and separate tangling config.org file.

Init.el

;;; package --- Summary
;;; Commentary:
;; The rest of the configuration is taken care in a separate file, at
;; the moment called config.org but may be named whatever sensible.

;;; Code:
(add-to-list 'load-path "~/.emacs.d/config/")

;; Check if the .org file has been updated
(when (file-newer-than-file-p "~/.emacs.d/config/config.org" "~/.emacs.d/config/config.el")
  (org-babel-load-file (expand-file-name "~/.emacs.d/config/config.org")))

(org-babel-load-file (expand-file-name "~/.emacs.d/config/config.el"))

(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)

(provide 'init)
;;; init.el ends here

Config.org

Emacs configuration

General

Exec-path etc.

Shell path for linux or osx systems

;; Let's set up essential package archives
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.org/packages/") t)
(unless package--initialized (package-initialize))

;; minimal UI
(menu-bar-mode -1) ;; disables menubar
(tool-bar-mode -1) ;; disables toolbar
(scroll-bar-mode -1) ;; disables scrollbar
(pixel-scroll-precision-mode 1) ;; enable smooth scrolling

(setq inhibit-splash-screen t ;; no thanks
      use-file-dialog nil ;; don't use system file dialog
      tab-bar-new-button-show nil ;; don't show new tab button
      tab-bar-close-button-show nil ;; don't show tab close button
      tab-line-close-button-show nil) ;; don't show tab close button

;; For ease of use, highly recommended to use this package
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(setq-default buffer-file-coding-system 'utf-8-unix)

(use-package exec-path-from-shell
  :ensure t
  :config
  (when (memq window-system '(mac ns x))
    (exec-path-from-shell-initialize)))

;; Backup files to another location
(setq backup-directory-alist `(("." . "~/.emacs.d/.saves")))

;; Org agenda files in this dir
(setq org-agenda-files nil)
(setq org-agenda-files '("~/notes"))

(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-file-name-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)

Appearance

Here are collection of delcarations and packages that mainly affects to appearance of emacs.

Window
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(add-hook 'server-after-make-frame-hook (lambda() (scroll-bar-mode -1)))
(global-display-line-numbers-mode 1)
Theme
;; Emacs themes
(use-package nord-theme
  :ensure t
  :init (load-theme 'nord t))
(add-to-list 'custom-theme-load-path (expand-file-name "~/.emacs.d/themes/"))
Doom-modeline
(use-package doom-modeline
  :ensure t
  :init (doom-modeline-mode 1))

;; Whether display the battery status. It respects `display-battery-mode'.
(setq doom-modeline-battery t)

;; Whether display the time. It respects `display-time-mode'.
(setq doom-modeline-time t)
Org bullets

Bullets may not work in terminal with default background unspecified. Changed e.g. #002b36 to unspecified-bg, and prefixed asterisks are ugly visible

(use-package org-bullets
  :ensure t
  :init (add-hook 'org-mode-hook (lambda ()(org-bullets-mode 1)
                                   (org-indent-mode))))

Let’s just set some cool bullets for orgbullets

(setq org-bullets-bullet-list '("󰯫"
                                "󰯮"
                                "󰯱"
                                "󰯷"
                                "󰯺"))
Nerd fonts
(use-package nerd-icons
  :ensure t
  :custom (nerd-icons-font-family "Symbols Nerd Font Mono")
  ;; The Nerd Font you want to use in GUI
  ;; "Symbols Nerd Font Mono" is the default and is recommended
  ;; but you can use any other Nerd Font if you want
  )
(use-package nerd-icons-completion
  :ensure t
  :after marginalia
  :config
  (nerd-icons-completion-mode)
  (add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup))

Usability packages

These packages helps you to use directories and files without breaking your nerves!

Indent bars
(use-package indent-bars
  :ensure t
  :hook ((python-mode jtsx-tsx-mode) . indent-bars-mode)) ; or whichever modes you prefer
Treemacs
    (use-package treemacs
    :ensure t
    :bind ("<f8>" . treemacs))

;  (require 'treemacs-nerd-icons)
 ; (treemacs-load-theme "nerd-icons")

    (use-package treemacs-nerd-icons
      :ensure t
      :after (treemacs nerd-icons)
      :config
      (treemacs-load-theme "nerd-icons"))
Drag-stuff
  (use-package drag-stuff
    :ensure t
    :bind (("C-S-<up>" . drag-stuff-up) ("C-S-<down>" . drag-stuff-down))
    :init (add-hook 'after-init-hook (lambda () (drag-stuff-global-mode 1))))

;  (with-eval-after-load 'org
 ;   (define-key org-mode-map [(control shift up)]  'drag-stuff-up)
  ;  (define-key org-mode-map [(control shift down)]  'drag-stuff-down))
Vertico
;; Enable vertico
(use-package vertico
  :custom
  ;; (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'
  :init
  (vertico-mode))

;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
  :init
  (savehist-mode))

;; A few more useful configurations...
(use-package emacs
  :custom
  ;; Support opening new minibuffers from inside existing minibuffers.
  (enable-recursive-minibuffers t)
  ;; Hide commands in M-x which do not work in the current mode.  Vertico
  ;; commands are hidden in normal buffers. This setting is useful beyond
  ;; Vertico.
  (read-extended-command-predicate #'command-completion-default-include-p)
  :init
  ;; Emacs bug#76028: Add prompt indicator to `completing-read-multiple'.
  ;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
(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))
Orderless
;; Optionally use the `orderless' completion style.
(use-package orderless
    :custom
      ;; Configure a custom style dispatcher (see the Consult wiki)
      ;; (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch))
      ;; (orderless-component-separator #'orderless-escapable-split-on-space)
      (completion-styles '(orderless basic))
        (completion-category-defaults nil)
        (completion-category-overrides '((file (styles partial-completion)))))`
Consult
;; Example configuration for Consult
(use-package consult
  ;; Replace bindings. Lazily loaded 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 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)
         ("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

  ;; 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

  ;; Tweak the register preview for `consult-register-load',
  ;; `consult-register-store' and the built-in commands.  This improves the
  ;; register formatting, adds thin separator lines, register sorting and hides
  ;; the window mode line.
  (advice-add #'register-preview :override #'consult-register-window)
  (setq register-preview-delay 0.5)

  ;; 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-man
   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.
  ;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
)
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)

  ;; Show the Embark target at point via Eldoc. You may adjust the
  ;; Eldoc strategy, if you want to see the documentation from
  ;; multiple providers. Beware that using this can be a little
  ;; jarring since the message shown in the minibuffer can be more
  ;; than one line, causing the modeline to move up and down:

  ;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
  ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)

  :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)))))

;; Consult users will also want the embark-consult package.
(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))
Marginalia
;; Enable rich annotations using the Marginalia package
(use-package marginalia
  :ensure t
  :init
  ;; Enable Marginalia globally to provide annotations in completion menus
  (marginalia-mode t))
Yasnippet
(use-package yasnippet
  :ensure t
  :init (yas-global-mode t))

(use-package yasnippet-snippets
  :ensure t)

Let’s also define paths for snippets, they will be organized all into their own folders and files.

(setq yas-snippet-dirs
      '("~/.emacs.d/snippets"                 ;; personal snippets
        "~/.emacs.d/elpa/yasnippet-snippets-20241207.2221/snippets")) ;; installed snippets

(yas-global-mode 1) ;; or M-x yas-reload-all if you've started YASnippet already.
Company-mode
;; (use-package company
;;   :ensure t
;;   :config
;;   (setq company-idle-delay 0
;;         company-minimum-prefix-length 2
;;         company-show-numbers t
;;         company-tooltip-limit 10
;;         company-tooltip-align-annotations t
;;         ;; invert the navigation direction if the the completion popup-isearch-match
;;         ;; is displayed on top (happens near the bottom of windows)
;;         company-tooltip-flip-when-above t)
;;   (global-company-mode t)
;;   )

;; ;;Different compaay backends below:
;; (use-package company-auctex
;;   :ensure t)

;; (defun my-org-hook ()
;;   (set (make-local-variable 'company-backends) '((:separate company-yasnippet company-capf) company-keywords)))
;;                                         ;      (setq-local company-backends '((:separate company-capf company-yasnippet company-keywords)))

;; (add-hook 'org-mode-hook #'my-org-hook)

;;  ;;(setq company-idle-delay
;;  ;;     (lambda () (if (company-in-string-or-comment) nil 0.1)))
Smartparens
(use-package smartparens
  :ensure t
  :init (require 'smartparens-config)
  :config (smartparens-global-mode t))
;(sp-pair "{" nil :actions :rem)
Flycheck
  (use-package flycheck
    :ensure t
    :config (global-flycheck-mode))

;  (with-eval-after-load 'flycheck
 ;   (add-hook 'flycheck-mode-hook #'flycheck-falco-rules-setup))
Maple minibuffer
;; (use-package maple-minibuffer
;;   :ensure nil
;;   :hook (after-init . maple-minibuffer-mode)
;;   :config
;;   (setq maple-minibuffer:position-type 'window-bottom-left
;;         maple-minibuffer:border-color "gray50"
;;         maple-minibuffer:height nil
;;         maple-minibuffer:width 0.7
;;         maple-minibuffer:cache t)

;;   (setq maple-minibuffer:action '(read-from-minibuffer read-string)
;;         maple-minibuffer:ignore-action '(evil-ex eval-expression))

;;   (add-to-list 'maple-minibuffer:ignore-action 'org-schedule)
;;   (add-to-list 'maple-minibuffer:ignore-regexp "^helm-")

;;   ;; more custom parameters for frame
;;   (defun maple-minibuffer:parameters ()
;;     "Maple minibuffer parameters."
;;     `((height . ,(or maple-minibuffer:height 10))
;;       (width . ,(or maple-minibuffer:width (window-pixel-width)))
;;       (left-fringe . 5)
;;       (right-fringe . 5))))
Beamer
(setq org-latex-listings 'minted
    org-latex-packages-alist '(("" "minted"))
    org-latex-pdf-process
    '("pdflatex -shell-escape -interaction=nonstopmode -output-directory=%o %f"))

Coding and versioning

LSP
(use-package lsp-mode
  :diminish "LSP"
  :ensure t
  :hook ((lsp-mode . lsp-diagnostics-mode)
         ;; Enable LSP for relevant modes
         ((tsx-ts-mode
           typescript-ts-mode
           js-ts-mode
           jtsx-tsx-mode) . lsp-deferred))
  :custom
  (lsp-keymap-prefix "C-c l")      ; Prefix for LSP actions
  (lsp-diagnostics-provider :flycheck)
  (lsp-completion-provider :none) ;; Use Corfu instead of LSP's built-in completion
  (lsp-session-file (locate-user-emacs-file ".lsp-session"))
  (lsp-log-io nil)                 ; Use only for debugging
  (lsp-keep-workspace-alive nil)    ; Close LSP server if buffers are closed
  (lsp-idle-delay 0.5)              ; Debounce timer
  (lsp-eslint-server-command '("vscode-eslint-language-server" "--stdio"))

  ;; Core functionality
  (lsp-enable-xref t)
  (lsp-auto-configure t)
  (lsp-eldoc-enable-hover t)
  (lsp-enable-dap-auto-configure t)
  (lsp-enable-file-watchers nil)
  (lsp-enable-folding t)
  (lsp-enable-imenu t)
  (lsp-enable-indentation nil)
  (lsp-enable-links nil)
  (lsp-enable-on-type-formatting nil)
  (lsp-enable-suggest-server-download t)
  (lsp-enable-symbol-highlighting t)
  (lsp-enable-text-document-color nil)

  ;; UI Configuration
  (lsp-ui-sideline-show-hover nil)
  (lsp-ui-sideline-diagnostic-max-lines 20)

  ;; Completion Setup (Using Vertico & Orderless)
  (lsp-completion-enable t)
  (lsp-completion-enable-additional-text-edit t)
  (lsp-enable-snippet t)
  (lsp-completion-show-kind t)

  ;; Headerline & Modeline
  (lsp-headerline-breadcrumb-enable t)
  (lsp-headerline-breadcrumb-enable-diagnostics nil)
  (lsp-headerline-breadcrumb-enable-symbol-numbers nil)
  (lsp-headerline-breadcrumb-icons-enable nil)
  (lsp-modeline-code-actions-enable nil)
  (lsp-modeline-diagnostics-enable nil)
  (lsp-modeline-workspace-status-enable nil)
  (lsp-signature-doc-lines 1)

  ;; Miscellaneous
  (lsp-ui-doc-use-childframe t)
  (lsp-eldoc-render-all nil)
  (lsp-lens-enable nil)
  (lsp-semantic-tokens-enable nil)

  :init
  (setq lsp-use-plists nil))

;; Ensure lsp-completion is properly enabled
(use-package lsp-completion
  :hook (lsp-mode . lsp-completion-mode))

;; Use `consult-completion-in-region' if Vertico is enabled.
;; Otherwise use the default `completion--in-region' function.
(setq completion-in-region-function
      (lambda (&rest args)
        (apply (if vertico-mode
                   #'consult-completion-in-region
                 #'completion--in-region)
               args)))
Eslint
(use-package lsp-eslint
   :demand t
   :after lsp-mode)
JTSX
(use-package jtsx
  :ensure t
  :init
  ;; Automatically use `jtsx--mode` for corresponding files
  (add-to-list 'auto-mode-alist '("\\.js\\'" . jtsx-jsx-mode))
  (add-to-list 'auto-mode-alist '("\\.jsx\\'" . jtsx-jsx-mode))
  (add-to-list 'auto-mode-alist '("\\.ts\\'" . jtsx-tsx-mode))
  (add-to-list 'auto-mode-alist '("\\.tsx\\'" . jtsx-tsx-mode)))
Yaml
(use-package yaml
  :ensure t)
Magit
(use-package magit
  :ensure t
  :bind (("C-x g" . magit-status)))

Misc

Some variable declarations and/or packages which might be useful too.

About

I will keep my emacs configuration file up to date here - feel free to use!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published