emacs.d-org/my-emacs.org

17 KiB

Configuración Emacs

Parámetros Iniciales

Early Init

En un arhivo diferente (early-init.el) que se carga antes de la configuración principal, colocamos los parámetros necesarios para configurar las opciones gráficas y de fuentes.

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

    (load-theme 'modus-operandi t)

    (set-face-attribute 'default nil :family "JetBrainsMono Nerd Font" :height 110)
    (set-face-attribute 'variable-pitch nil :family "Ubuntu Nerd Font" :height 120)

    (setq frame-resize-pixelwise t)

Bash

Colocamos un alias en nuestra shell (bash)

  alias ec='emacsclient -cn'
  alias et='emacsclient -t'

Opciones de Emacs

Lexical Binding

  ;; -*- lexical-binding: t -*-

Fichero de configuración de variables (automático)

  (setq custom-file (concat user-emacs-directory "custom.el"))
  (load custom-file :noerror)

Configuración de opciones básicas

    (use-package emacs
      :ensure nil
      :init
      (setq tab-always-indent 'complete)          ;; Corfu creator suggestion
      (setq warning-minimum-level :error)         ;; supress warning messages
      ;; Files
      (setq backup-directory-alist                ;; backup files
            '(("." . "~/.config/emacs/file-backups"))
            delete-by-moving-to-trash t)
      ;; Desktop and layout
      (desktop-save-mode 1)
      ;; Misc
      (setq calendar-week-start-day 1)
      :config
      (delete-selection-mode 1)
      (savehist-mode 1)
      (column-number-mode 1)
      (fset 'yes-or-no-p 'y-or-n-p)       ;; yes or no to y or n
      (electric-pair-mode 1)
      (global-auto-revert-mode 1)
      (global-visual-line-mode t)
      :bind ("<f5>" . toggle-theme)
      :hook ((prog-mode conf-mode) . display-line-numbers-mode))

    ;; ;; Disable line numbers for some modes
    ;; (dolist (mode '(term-mode-hook
    ;;                 eat-mode-hook
    ;;                 shell-mode-hook
    ;;                 vterm-mode-hook
    ;;                 org-mode-hook
    ;;                 elfeed-show-mode-hook
    ;;                 elfeed-search-mode-hook
    ;;                 org-agenda-mode-hook
    ;;                 pdf-view-mode-hook
    ;;                 treemacs-mode-hook
    ;;                 eshell-mode-hook))
    ;;   (add-hook mode (lambda () (display-line-numbers-mode 0))))

    ;; (global-display-line-numbers-mode 1)

Archivos

Abrir archivos recientes
  (use-package recentf
    :init
    (setq recentf-max-menu-items 50)
    :bind ("C-x C-r" . recentf-open-files)
    :config (recentf-mode t))

Gestión de Paquetes

  (require 'package)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  (package-initialize)

  (require 'use-package)
  (setq use-package-always-ensure t
        use-package-verbose t)

Interfaz

Gestión de Ventanas

  (use-package ace-window
  :ensure t
  :bind ("M-o" . ace-window)
  :config
  (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))

Movimientos en buffer

  (use-package avy
    :bind ("C-:" . 'avy-goto-char))

Minibuffer

  (use-package marginalia
    :init (marginalia-mode))

  (use-package orderless
    :custom
    (completion-styles '(orderless partial-completion basic))
    (completion-category-defaults nil)
    (completion-category-overrides nil))

  (use-package vertico
    :init
    (vertico-mode)
    (setq vertico-cycle t)
    :bind (("\M-R" . vertico-repeat)
           :map vertico-map
           ("M-q" . vertico-quick-insert)
           ("C-q" . vertico-quick-exit))
    :hook (minibuffer-setup . vertico-repeat-save))

Autocompletado

Corfu

    (defun my/eglot-capf ()
      (setq-local completion-at-point-functions
                  (list (cape-capf-super
                         #'eglot-completion-at-point
                         #'tempel-expand
                         #'cape-file))))
    (add-hook 'eglot-managed-mode-hook #'my/eglot-capf)

    (use-package corfu
      :config
      (setq corfu-auto t
            corfu-auto-delay 0.3
            corfu-auto-prefix 2
            global-corfu-modes '((not
                                  shell-mode)
                                 t))
      :init
      (global-corfu-mode)

Cape

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

  (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)

  (defun my/eglot-capf ()
    (setq-local completion-at-point-functions
                (list (cape-capf-super
                       #'eglot-completion-at-point
                       #'tempel-expand
                       #'cape-file))))
  (add-hook 'eglot-managed-mode-hook #'my/eglot-capf)

DONE Tempel

  • Alternativa a Yasnippet

      (use-package tempel
        :bind (("M-+" . tempel-complete)
               ("M-*" . tempel-insert))
        :init
        ;; Setup completion at point
        (defun tempel-setup-capf ()
          ;; Add the Tempel Capf to `completion-at-point-functions'.
          ;; `tempel-expand' only triggers on exact matches. Alternatively use
          ;; `tempel-complete' if you want to see all matches, but then you
          ;; should also configure `tempel-trigger-prefix', such that Tempel
          ;; does not trigger too often when you don't expect it. NOTE: We add
          ;; `tempel-expand' *before* the main programming mode Capf, such
          ;; that it will be tried first.
          (setq-local completion-at-point-functions
                      (cons #'tempel-expand
                            completion-at-point-functions)))
    
        (add-hook 'conf-mode-hook 'tempel-setup-capf)
        (add-hook 'prog-mode-hook 'tempel-setup-capf)
        (add-hook 'text-mode-hook 'tempel-setup-capf)
    
        ;; Optionally make the Tempel templates available to Abbrev,
        ;; either locally or globally. `expand-abbrev' is bound to C-x '.
        ;; (add-hook 'prog-mode-hook #'tempel-abbrev-mode)
        ;; (global-tempel-abbrev-mode)
        )
    
      ;; Optional: Add tempel-collection.
      ;; The package is young and doesn't have comprehensive coverage.
      (use-package tempel-collection
        :after tempel)

TODO Yasnippet

Falta por configurar los snippets, de momento solo tengo el motor

  (use-package yasnippet)

Utilidades

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

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

Org Mode

Org-Modern

hi

  (use-package org-modern
    :init
    (setq org-hide-emphasis-markers t
          org-pretty-entities t
          org-ellipsis "…")
    :config
    (global-org-modern-mode))

Lsp

Eglot

  (use-package eglot
    :config
    (setq-default eglot-workspace-configuration
                  '((:pylsp . (:configurationSources ["flake8"] :plugins (:flake8 (:enabled t))))))
    :hook '((python-mode . eglot-ensure)
            (sh-mode . eglot-ensure)))

Lenguajes

Python

  (setq major-mode-remap-alist
      '((python-mode . python-ts-mode)))

TODO Markdown

Falta las opciones

    (use-package markdown-mode
      :defer t)

TODO Typescript

  (use-package typescript-ts-mode
    :defer t
    :mode (("\\.ts\\'" . typescript-ts-mode)
           ("\\.tsx\\'" . tsx-ts-mode))
    :hook ((typescript-ts-mode tsx-ts-mode) . eglot-ensure))

  ;; (define-derived-mode typescriptreact-mode typescript-ts-mode
  ;;   "TypeScript TSX")

  ;; (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescriptreact-mode))

  ;; (use-package 

  ;; (defun setup-tide-mode ()
  ;;   (interactive)
  ;;   (tide-setup)
  ;;   (flycheck-mode +1)
  ;;   (setq flycheck-check-syntax-automatically '(save mode-enabled))
  ;;   (eldoc-mode +1))

  ;;   (use-package tide
  ;;   :hook ((typescript-ts-mode . tide-setup)
  ;;          (tsx-ts-mode . tide-setup)
  ;;          (typescript-ts-mode . tide-hl-identifier-mode)))

Clojure

CIDER
    (use-package cider
      :defer t)

Desarrollo

Docker

    (use-package dockerfile-mode
      :defer t)

Terminales

EAT

  (use-package eat
  :defer t
  :init
  ;; make cat long files boosted
  (setq process-adaptive-read-buffering nil
        read-process-output-max (* 4 1024 1024))
  :config
  (eat-eshell-mode 1)
  (setq eshell-visual-commands '()))

fish

    (use-package fish-mode
      :defer t)

Social

RSS

  (use-package elfeed
    :bind ("C-x w" . elfeed)
    :config
    (setq elfeed-feeds
          '(("https://planet.emacslife.com/atom.xml" emacs)
            ("https://victorhck.gitlab.io/planetalibre/feed.xml" Linux)
            ("https://atareao.es/feed" Linux Español)
              )))

Mastodon

  (use-package mastodon
    :ensure t
    :defer t
    :hook (mastodon-mode . variable-pitch-mode))

  (setq mastodon-instance-url "https://fe.disroot.org"
        mastodon-active-user "@enriquemp@fe.disroot.org")

  (use-package emojify
    :hook (after-init . global-emojify-mode))

Multimedia

EMMS

  (use-package emms
    :ensure t
    :init
    (require 'emms-setup)
    (require 'emms-mpris)
    (emms-all)
    (emms-default-players)
    (emms-mpris-enable)
    :hook
    (emms-browser-mode . hl-line-mode)
    :custom
    (setq emms-player-list '(emms-player-mpv))
    (setq emms-info-functions '(emms-info-native))
    (setq emms-source-file-default-directory "~/Music/")
    (emms-browser-covers #'emms-browser-cache-thumbnail-async)
    :bind (("<f6>" . emms-browser)
           ("M-<f6>" . emms)
           ("<XF86AudioPrev>" . emms-previous)
           ("<XF86AudioNext>" . emms-next)
           ("<XF86AudioPlay>" . emms-pause)))

Miscelánea

Which-Key (repo)

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

AI

ChatGPT
  (use-package chatgpt-shell
    :defer t
    :custom
    ((chatgpt-shell-openai-key "YOUR_API_KEY_HERE")))

TLDR

Emacs UI for great utils

    (use-package tldr
      :defer t)

Test

gnus email

  (setq gnus-select-method '(nnnil nil))
  (setq gnus-secondary-select-methods
        '((nnimap "disroot"
                  (nnimap-address "disroot.org")
                  (nnimap-server-port "993")
                  (nnimap-stream ssl)
                  (nnir-search-engine imap)
                  (nnmail-expiry-target "nnimap+home:[Example]/Trash")
                  (nnmail-expiry-wait 'inmediate))))

  (setq gnus-asynchronous t
        gnus-use-cache t
        gnus-use-header-prefetch t)