You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 KiB

Before this file loads

early-init.el has been loaded.

This file inhibits package.el for loading packages

init.el has been loaded

This file:

  • Set all that it's needed for straight.el working as package manager
  • IMPORTANT Changes the user-emacs-directory from ~/.emacs.d to ~/.cache/emacs. This can be really important in case you change something fundamental in emacs configuration
  • Load the no-littering package (see doc) This package sets out to fix this by changing the values of path variables to put configuration files in no-littering-etc-directory (this will be ~/.cache/emacs/etc/ for this configuration) and persistent data files in no-littering-var-directory (for me: ~/.cache/emacs/var/), and by using descriptive file names and subdirectories when appropriate. This is similar to a color-theme; a "path-theme" if you will.
  • Tries to install org-mode just to be sure to have the last release
  • Loads the newer of this two files: myconfig.org and myconfig.el. In other words, if there are no new changes in myconfig.org it loads myconfig.el (it's faster)

use-package tips

Some notes about use-package

  • :ensure if true will install the package if not installed It won't update packages. See auto-package-update for keeping all packages up to date
  • :init keyword to execute code before a package is loaded. It accepts one or more forms, up to the next keyword
  • :config can be used to execute code after a package is loaded. In cases where loading is done lazily (see more about autoloading below), this execution is deferred until after the autoload occurs
  • :custom permite configurar variables con syntaxis simplificada
  • :bind
  • :bind-keymap
  • :commands
  • :mode and :interpreter
  • :magic
  • :hook You can define hooks
  • :if
  • :defer En general use-package intenta aplicar lazy loading, pero en algún paquete es necesario especificarlo explicitamente
  • :demand Este es el contrario del anterior, para paquetes que queremos cargar de inmediato
  • :diminish and :delight changes minormode display in status line

Personal info

(setq user-full-name "Sergio Alvariño"
      user-mail-address "salvari@protonmail.com")

Interface tweaks

Some GUI optimizations

  ;; sets default font
  (set-face-attribute 'default nil :family "Mensch" :foundry "PfEd" :height 158)

  (setq inhibit-x-resources t)              ; avoid problems with emacs daemon and cursor colors
  (setq inhibit-startup-message t)          ; Eliminate FSF startup msg
  (setq frame-title-format "%b")            ; Put filename in titlebar
  (setq visible-bell t)                     ; Flash instead of beep
  (set-scroll-bar-mode 'right)              ; Scrollbar placement
  (show-paren-mode t)                       ; Blinking cursor shows matching parentheses
  (electric-pair-mode t)                    ; electric-pair-mode on
  (setq column-number-mode t)               ; Show column number of current cursor location
  (mouse-wheel-mode t)                      ; wheel-mouse support
  (setq fill-column 78)
  (setq auto-fill-mode t)                   ; Set line width to 78 columns...
  (setq-default indent-tabs-mode nil)       ; Insert spaces instead of tabs
  (setq-default tab-width 4)                ; set default tab 4 spaces
  (global-set-key "\r" 'newline-and-indent) ; turn autoindenting on
  ;(set-default 'truncate-lines t)          ; Truncate lines for all buffers
  (fset 'yes-or-no-p 'y-or-n-p)             ; shorter messages
  (setq sentence-end-double-space nil)      ; only one space
  ; delete trailing whitespace before saving
  (add-hook 'before-save-hook 'delete-trailing-whitespace)
  ;; Enable line numbers for some modes
  (dolist (mode '(;;text-mode-hook
                  prog-mode-hook
                  conf-mode-hook))
    (add-hook mode (lambda () (display-line-numbers-mode 1))))

  ;; Override some modes which derive from the above
  (dolist (mode '(org-mode-hook))
    (add-hook mode (lambda () (display-line-numbers-mode 0))))

Set encoding

Use utf-8 please

  ;; Set encoding
  (prefer-coding-system 'utf-8)

Some shortcuts

Useful shortcuts:

  • Revert buffer (recargar)
  • fichero org de configuración de emacs
  • fichero org ppal, aquí está todo
  • journal org file
  • org para el blog público, ideas para el blog
  • org para el blog privado
  • org notes file: para tomar una nota rápida, no lo uso mucho
  • phone org file: por si tomo notas en el teléfono, no lo uso mucho
  (global-set-key (kbd "<f5>") 'revert-buffer)
  ;; emacs configuration org file
  (global-set-key
   (kbd "\e\ec")
   (lambda () (interactive) (find-file "~/.emacs.d/myconfig.org")))
  ;; Main org file
  (global-set-key
   (kbd "\e\ei")
   (lambda () (interactive) (find-file "~/Dropbox/orgfiles/i.org")))
  ;; journal org file
  (global-set-key
   (kbd "\e\ej")
   (lambda () (interactive) (find-file "~/Dropbox/orgfiles/journal.org")))
  ;; Notes file
  (global-set-key
   (kbd "\e\en")
   (lambda () (interactive) (find-file "~/Dropbox/orgfiles/notes.org")))
  ;; public blog org file
  (global-set-key
   (kbd "\e\eb")
   (lambda () (interactive) (find-file "~/Dropbox/orgfiles/b.org")))
  ;; private blog file
  (global-set-key
   (kbd "\e\ep")
   (lambda () (interactive) (find-file "~/work/repos/Personal/blog/comacero_priv/content-org/blog_privado.org")))
  ;; phone org file
  (global-set-key
   (kbd "\e\eh")
   (lambda () (interactive) (find-file "~/share/Mob_orgzly/phone.org")))

  (global-set-key [C-tab] 'hippie-expand)                    ; expand
  (global-set-key [C-kp-subtract] 'undo)                     ; [Undo]
  ;; (global-set-key [C-kp-multiply] 'goto-line)             ; old goto line
  (global-set-key [C-kp-multiply] 'consult-goto-line)        ; goto line
  (global-set-key [C-kp-add] 'toggle-truncate-lines)         ; truncate lines
  (global-set-key [C-kp-divide] 'delete-trailing-whitespace) ; delete trailing whitespace
  (global-set-key [C-kp-decimal] 'completion-at-point)       ; complete at point
  (global-set-key [C-M-prior] 'previous-buffer)              ; previous-buffer
  (global-set-key [C-M-next] 'next-buffer)                   ; next-buffer

Own map

Defines own key map

  (define-prefix-command 'own-map)
  (global-set-key (kbd "C-ñ") 'own-map)
  (define-key own-map (kbd "y") 'aya-create)
  (define-key own-map (kbd "e") 'aya-expand)

General (a new binding system)

Have a look at doc

  ;; (use-package general)

Syntax highlight

Set maximum colors

  (cond ((fboundp 'global-font-lock-mode)        ; Turn on font-lock (syntax highlighting)
         (global-font-lock-mode t)               ; in all modes that support it
         (setq font-lock-maximum-decoration t))) ; Maximum colors

Kill buffer quick

Kill current buffer without questions

  ;;------------------------------------------------------------
  ;; Kill current buffer with C-Supr
  (defun slv-kill-buffer ()
    ;; Kill default buffer without the extra emacs questions
    (interactive)
    (kill-buffer (buffer-name))
    (set-name))
  (global-set-key [C-delete] 'slv-kill-buffer)

rainbow-delimiters

  (use-package rainbow-delimiters
    :hook (prog-mode . rainbow-delimiters-mode)
    )

which-key

Some help with composed hotkeys

  (use-package which-key
    :diminish
    :config
    (which-key-mode)
    (setq which-key-idle-delay 0.3)
    )

ace-windows

To jump to different windows easily

  (use-package ace-window
    :init
    (global-set-key [remap other-window] 'ace-window)
    (custom-set-faces
     '(aw-leading-char-face
       ((t (:inherit ace-jump-face-foreground :height 3.0)))))
    )

PCRE2el

Perl Compatible Regexes

  (use-package pcre2el
    :config
    (pcre-mode +1))

Enable narrowing (DANGER)

C-x n …

  (put 'narrow-to-defun  'disabled nil)
  (put 'narrow-to-page   'disabled nil)
  (put 'narrow-to-region 'disabled nil)

doom-modeline

A fancy modeline. Remember to execute M-x all-the-icons-install-fonts See this for fixing icons in terminal

  (use-package all-the-icons
    )
  (use-package doom-modeline
    :init
    (doom-modeline-mode 1)
    (setq doom-modeline-icon 1) ;; this fixes icons in emacs-client
    :custom
    (doom-modeline-height 15)
    ;;(doom-modeline-icon (display-graphic-p))
    )

color-theme

  ;; (use-package modus-operandi-theme)
  (use-package modus-themes)
  ;; (load-theme 'modus-operandi t)
  ;; (load-theme 'modus-vivendi t)

  (use-package doom-themes
    :config
    ;; Global settings (defaults)
    (setq doom-themes-enable-bold t    ; if nil, bold is universally disabled
          doom-themes-enable-italic t) ; if nil, italics is universally disabled
    (load-theme 'doom-vibrant t)

    ;; Enable flashing mode-line on errors
    (doom-themes-visual-bell-config)

    ;; Enable custom neotree theme (all-the-icons must be installed!)
    (doom-themes-neotree-config)

    ;; or for treemacs users
    (setq doom-themes-treemacs-theme "doom-colors") ; use the colorful treemacs theme
    (doom-themes-treemacs-config)

    ;; Corrects (and improves) org-mode's native fontification.
    (doom-themes-org-config)
    )

Completion systems

Vertico (the choosed one)

Have a look here

  (use-package vertico
    :init
    (vertico-mode +1)
    :config
    ;; Different scroll margin
    ;; (setq vertico-scroll-margin 0)

    ;; Show more candidates
    ;; (setq vertico-count 20)

    ;; Grow and shrink the Vertico minibuffer
    ;; (setq vertico-resize t)

    ;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
    (setq vertico-cycle t)
    )

Orderless

Have a look at repo

  (use-package orderless
    :init
    (icomplete-mode)
    :custom
    (completion-styles '(orderless))
    (completion-category-defaults nil)
    (completion-category-overrides '((file (styles partial-completion))))
    )

Marginalia

Check the doc

  (use-package marginalia
  :init
  (marginalia-mode +1)
  :bind
  (; ("M-A" . marginalia-cycle)    ;; Uncomment for global bind
   :map minibuffer-local-map
   ("M-A" . marginalia-cycle))
  )

Consult and Embark

Consult is a collection of programs using emacs completing-read You must read the doc!

  (use-package consult
    :bind (("C-c h" . consult-history)
           ("C-c m" . consult-mode-command)
           ("C-c k" . consult-kmacro)
           ;; C-x bindings (ctl-x-map)
           ("C-s" . consult-line)                    ; orig. isearch-forward
           ("C-c j" . consult-imenu)
           ("C-x M-:" . consult-complex-command)     ; orig. repeat-complex-command
           ("C-x b" . consult-buffer)                ; orig. switch-to-buffer
           :map minibuffer-local-map
           ("C-r" . consult-history)
           )
    )

Embark

The doc

  (use-package embark
    :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)

    :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
    :after (embark consult)
    :demand t ; only necessary if you have the hook below
    ;; if you want to have consult previews as you move around an
    ;; auto-updating embark collect buffer
    :hook
    (embark-collect-mode . consult-preview-at-point-mode))

Editor Enhancements

ace-windows

To jump to different windows easily

  (use-package ace-window
    :ensure t
    :init
    (global-set-key [remap other-window] 'ace-window)
    (custom-set-faces
     '(aw-leading-char-face
       ((t (:inherit ace-jump-face-foreground :height 3.0)))))
    )

ripgrep

rg repo

  (use-package rg
    :bind
    ("C-c s" . rg-menu))

Buffer management

Bufler repo

  (use-package bufler
    )
  (defun sap/bufler-one-window (&optional force-refresh)
    (interactive "P")
    (bufler-list)
    (delete-other-windows)
    )

  (global-set-key (kbd "C-x C-b") 'sap/bufler-one-window)

Hydra

Hydra repo See this someday

  (use-package hydra)

Hydra for toggle

  (global-set-key
   (kbd "<f6> t")
   (defhydra hydra-toggle (:color pink)
     "
     _a_ abbrev-mode:       %`abbrev-mode
     _d_ debug-on-error:    %`debug-on-error
     _f_ auto-fill-mode:    %`auto-fill-function
     _l_ disp-line-num      %`display-line-numbers-mode
     _s_ flyspell-mode:     %`flyspell-mode
     _t_ truncate-lines:    %`truncate-lines
     _w_ whitespace-mode:   %`global-whitespace-mode
     "
     ("a" abbrev-mode nil)
     ("d" toggle-debug-on-error nil)
     ("f" auto-fill-mode nil)
     ("l" display-line-numbers-mode nil)
     ("s" flyspell-mode nil)
     ("t" toggle-truncate-lines nil)
     ("w" whitespace-mode nil)
     ("q" nil "quit"))
   )

Hydra for navigation

  (global-set-key
   (kbd "<f6> j")
   (defhydra gotoline
     (:pre (linum-mode 1)
           :post (linum-mode -1))
     "goto"
     ("t" (lambda () (interactive)(move-to-window-line-top-bottom 0)) "top" :column "Window")
     ("b" (lambda () (interactive)(move-to-window-line-top-bottom -1)) "bottom")
     ("m" (lambda () (interactive)(move-to-window-line-top-bottom)) "middle")
     ("c" recenter-top-bottom "recenter")
     ("s" (lambda () (interactive)(beginning-of-buffer)) "begin" :column "Buffer")
     ("e" (lambda () (interactive)(end-of-buffer)) "end")
     ("n" next-line "down" :column "Line")
     ("p" (lambda () (interactive) (forward-line -1))  "up")
     ("g" goto-line "consult-goto-line")
     ("i" consult-imenu "cons-imenu" :column "Header")
     ("o" consult-org-heading "cons-org-head")
     ("q" nil "quit")
     )
   )

avy

Quick navigation to words

  (use-package avy
    :config
    (avy-setup-default)
    :bind(
          :map own-map
          ("jj" . avy-goto-char)
          ("j2" . avy-goto-char-2)
          ("jw" . avy-goto-word-1)
          ("jl" . avy-goto-line)
       )
    )

iedit

iedit: Interactive edition of all ocurrences of X

  (use-package iedit
    :bind
    ("C-ç" . iedit-mode))

Project management with projectile

  (use-package projectile
    :init
    (projectile-global-mode)
    :config
    (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
    )

Git management

All you need for git

  • magit interface to git from emacs (there are a lot of tutos)
  • git-gutter See lines changed in buffer edited
  • git-time-machine Visit previous git versions of edited buffer
  ;; dirty hack to avoid problem when pushing
  (setenv "SSH_AUTH_SOCK" "/run/user/1000/keyring/ssh")

  (use-package magit
    :bind
    ("C-x g" . magit-status)
    :config
    (setq magit-status-margin
        '(t "%Y-%m-%d %H:%M " magit-log-margin-width t 18))
  )

  (use-package git-gutter
    :init
    (global-git-gutter-mode +1)
    )
    (defhydra hydra-git-gutter (:body-pre (git-gutter-mode 1)
                                          :hint nil)
      "
      Git gutter:
        _j_: next hunk        _s_tage hunk     _q_uit
        _k_: previous hunk    _r_evert hunk    _Q_uit and deactivate git-gutter
        ^ ^                   _p_opup hunk
        _h_: first hunk
        _l_: last hunk        set start _R_evision
      "
      ("j" git-gutter:next-hunk)
      ("k" git-gutter:previous-hunk)
      ("h" (progn (goto-char (point-min))
                  (git-gutter:next-hunk 1)))
      ("l" (progn (goto-char (point-min))
                  (git-gutter:previous-hunk 1)))
      ("s" git-gutter:stage-hunk)
      ("r" git-gutter:revert-hunk)
      ("p" git-gutter:popup-hunk)
      ("R" git-gutter:set-start-revision)
      ("q" nil :color blue)
      ("Q" (progn (git-gutter-mode -1)
                  ;; git-gutter-fringe doesn't seem to
                  ;; clear the markup right away
                  (sit-for 0.1)
                  (git-gutter:clear))
       :color blue))
    (global-set-key (kbd "M-g M-g") 'hydra-git-gutter/body)

  (use-package git-timemachine
    )

yasnippet

Place your own snippets on ~/.cache/emacs/etc/yasnippet/snippets

  (use-package yasnippet
    :init
    (yas-global-mode 1)
    )
  (use-package auto-yasnippet
    )
  (use-package yasnippet-snippets
    )

company

Autocompletion with company

  (use-package company
    :init
    (global-company-mode t)

    :config
    ;; (setq company-idle-delay 0)
    (setq company-idle-delay
          (lambda () (if (company-in-string-or-comment) nil 0.3)))
    (setq company-minimum-prefix-length 3)
    ;; (add-to-list 'company-backends 'company-yasnippet t)

    :bind
    ("C-<iso-lefttab>" . company-complete-common-or-cycle)
    )

company-quickhelp

In case you want popup help instead of status line help

  (use-package company-quickhelp
    :config
    (company-quickhelp-mode)
    ;; (setq company-quickhelp-delay nil)   ; Uncoment to disable quickhelp (default 0.5)
  )

company-lsp (DEPRECATED)

;;  (use-package company-lsp
;;    :ensure
;;    :config
;;    (push 'company-lsp company-backends)
;;    )

org-mode

org-bullets

Nice bullets for org-mode

  (use-package org-bullets
    :config
    (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
    )

LSP

We are using lsp-mode but keep an eye on eglot as an alternative. WARNING: lsp-company is no longer supported

Links to check

LSP mode, allows the use of Language Server Protocol for programming.

lsp-keymap prefix remapped to "C-c l"

  (use-package lsp-mode
    :init
    (setq lsp-keymap-prefix "C-c l")

    :commands
    (lsp lsp-deferred lsp-execute-code-action)

    :custom
    ;; debug
    ;; set these variables for debugging lsp-mode
    (lsp-print-io t)
    (lsp-trace t)
    (lsp-print-performance t)

    ;; general
    ;; (lsp-auto-guess-root t)                 ;; Probably you want to choose root interactively
    ;; (lsp-document-sync-method 'incremental) ;; none, full, incremental, or nil
    ;; (lsp-response-timeout 10)

    ;; let's use flycheck
    (lsp-prefer-flymake nil) ;; t(flymake), nil(lsp-ui), or :none

    ;; (company-lsp-cache-candidates t) ;; auto, ;TODO: (always using a cache), or nil
    ;; (company-lsp-async t)
    ;; (company-lsp-enable-recompletion t)
    ;; (company-lsp-enable-snippet t)

    ;; (lsp-eldoc-render-all nil)

    ;;   :hook
    ;;   ((python-mode . lsp-deferred)
    ;;    (lsp-mode . lsp-enable-which-key-integration)
    ;;    (lsp-mode . lsp-diagnostics-modeline-mode))
    ;;   :bind
    ;;   ("C-c C-c" . #'lsp-execute-code-action)
    ;;   :custom
    ;;   (lsp-diagnostics-modeline-scope :project)
    ;;   (lsp-file-watch-threshold 5000)
    ;;   (lsp-enable-file-watchers nil)
    ;;   ;(lsp-enable-which-key-integration t)
    )

lsp-ui

  (use-package lsp-ui
    :custom
    (lsp-ui-doc-delay 0.75)
    (lsp-ui-doc-max-height 200)

    (lsp-ui-doc-enable t)
    (lsp-ui-doc-header t)
    (lsp-ui-doc-include-signature t)
    (lsp-ui-doc-max-height 30)
    (lsp-ui-doc-max-width 120)
    (lsp-ui-doc-position (quote at-point))
    (lsp-ui-doc-use-childframe t)
    ;;
    ;; ;; If this is true then you can't see the docs in terminal
    ;; (lsp-ui-doc-use-webkit nil)
    (lsp-ui-flycheck-enable t)
    ;;
    ;; (lsp-ui-imenu-enable t)
    ;; (lsp-ui-imenu-kind-position (quote top))
    (lsp-ui-peek-enable t)
        (lsp-ui-peek-fontify 'on-demand) ;; never, on-demand, or always
    (lsp-ui-peek-list-width 50)
    (lsp-ui-peek-peek-height 20)

    (lsp-ui-sideline-code-actions-prefix "" t)
    ;;
    ;;                                       ;inline right flush docs
    (lsp-ui-sideline-enable t)
    (lsp-ui-sideline-ignore-duplicate t)
    (lsp-ui-sideline-show-code-actions t)
    (lsp-ui-sideline-show-diagnostics t)
    (lsp-ui-sideline-show-hover t)
    (lsp-ui-sideline-show-symbol t)

    :after lsp-mode)

lsp-treemacs

Try these commands with M-x:

  • lsp-treemacs-symbols - Show a tree view of the symbols in the current file
  • lsp-treemacs-references - Show a tree view for the references of the symbol under the cursor
  • lsp-treemacs-error-list - Show a tree view for the diagnostic messages in the project
  (use-package lsp-treemacs
    :after lsp)

DAP mode

DAP-mode is an excellent package for bringing rich debugging capabilities to Emacs via the Debug Adapter Protocol. You should check out the configuration docs to learn how to configure the debugger for your language. Also make sure to check out the documentation for the debug adapter to see what configuration parameters are available to use for your debug templates!

  ;; (use-package dap-mode
  ;;   ;; Uncomment the config below if you want all UI panes to be hidden by default!
  ;;   ;; :custom
  ;;   ;; (lsp-enable-dap-auto-configure nil)
  ;;   ;; :config
  ;;   ;; (dap-ui-mode 1)
  ;;   :config
  ;;   ;; Set up Node debugging
  ;;   (require 'dap-node)
  ;;   (dap-node-setup) ;; Automatically installs Node debug adapter if needed
  ;; 
  ;;   ;; Bind `C-c l d` to `dap-hydra` for easy access
  ;;   ;;(general-define-key
  ;;   ;;  :keymaps 'lsp-mode-map
  ;;   ;;  :prefix lsp-keymap-prefix
  ;;   ;;  "d" '(dap-hydra t :wk "debugger"))
  ;;   )

go

WARNING: you need to install gopls in your system. WARNING: company-go is deprecated, don't use it References:

  (use-package go-mode
     :custom
     ;; (lsp-enable-links nil)
     ;; (lsp-clients-go-server-args '("--cache-style=always" "--diagnostics-style=onsave" "--format-style=goimports"))
     (lsp-gopls-server-args '("--debug=localhost:6060"))
     :hook
     ((go-mode . lsp-deferred)
      (before-save . lsp-format-buffer)
      (before-save . lsp-organize-imports)
      (before-save . gofmt-before-save)
      )
     )

go-snippets

  (use-package go-snippets
    :after go-mode
    )

got-projectile

  ;; (use-package go-projectile
  ;;   )

go-test

  (use-package gotest
    :bind
    (:map go-mode-map
          ("C-c a t" . #'go-test-current-test)
          )
    )

Python

next