Files
confi-emacs-actual/configs/init-utils.el
kj dabaf86f28 Big re-write :)
I reordered the code in a more clean an organized way. Also this improves a lot
the emacs startup time again, bucause after some updates it becomes a bit slow
with the old configuration, so i did it again in a new way.
2025-07-20 13:18:05 -03:00

242 lines
9.2 KiB
EmacsLisp

;; init-utils.el --- Initialize ultilities. -*- lexical-binding: t -*-
;; Author: kj <webmaster@outcontrol.net>
;; URL: https://git.kj2.me/kj/confi-emacs-actual
;;; Commentary:
;;
;; Some usefule Utilities.
;;
;;; Code:
;; Mejora del reemplazo
(use-package anzu
:bind (([remap query-replace] . anzu-query-replace)
([remap query-replace-regexp] . anzu-query-replace-regexp)))
;; Intercamiar buffers de lugar
(use-package buffer-move
:bind (("M-S-<up>" . buf-move-up)
("M-S-<down>" . buf-move-down)
("M-S-<left>" . buf-move-left)
("M-S-<right>" . buf-move-right))
)
;; Cuando inicias un atajo de teclas te muestra las posibilidades
(use-package which-key
:diminish
:init (setq which-key-max-description-length 30
which-key-lighter nil
which-key-show-remaining-keys t)
:autoload which-key-posframe-mode
:hook ( elpaca-after-init . which-key-mode))
;; Muestra which-key en un frame en el centro en lugar de abajo
(when (childframe-workable-p)
(use-package which-key-posframe
:diminish
:defines posframe-border-width
:functions posframe-poshandler-frame-center-near-bottom
:custom-face
(which-key-posframe ((t (:inherit tooltip))))
(which-key-posframe-border ((t (:inherit posframe-border :background unspecified))))
:init
(setq which-key-posframe-border-width posframe-border-width
which-key-posframe-poshandler #'posframe-poshandler-frame-center-near-bottom
which-key-posframe-parameters '((left-fringe . 8)
(right-fringe . 8)))
(which-key-posframe-mode 1)))
;; Fast search tool `ripgrep'
(use-package rg
:hook (after-init . rg-enable-default-bindings)
:bind (:map rg-global-map
("c" . rg-dwim-current-dir)
("f" . rg-dwim-current-file)
("m" . rg-menu))
:init (setq rg-show-columns t)
:config (add-to-list 'rg-custom-type-aliases '("tmpl" . "*.tmpl")))
;; Process
(use-package proced
:ensure nil
:init
(setq-default proced-format 'verbose)
(setq proced-auto-update-flag t
proced-auto-update-interval 3
proced-enable-color-flag t))
;; Paquete para exportar buffers de emacs a HTML
(use-package htmlize)
;; eww
(use-package eww
:ensure nil
:init
;; Install: npm install -g readability-cli
(when (executable-find "readable")
(setq eww-retrieve-command '("readable"))))
;; Restaurar el estado de los frames
(use-package winner
:ensure nil
:config
(winner-mode))
;; Terminal
(use-package vterm
:config
(setq tramp-histfile-override nil) ;; Dejamos que se use el history por defecto del servidor remoto
(setq vterm-tramp-shells '(("ssh" "/bin/bash")
("sshx" "/bin/bash")
("docker" "/bin/bash")
("podman" "/bin/bash"))) ;; Tanto docker como podman usarán bash cuado se contecte mediante tramp
)
;; Multiple vterm
(use-package multi-vterm
:after vterm
:bind* (("<f5>" . multi-vterm-dedicated-toggle)
("C-x tt" . multi-vterm-dedicated-toggle)
("C-x tf" . multi-vterm)
("C-x tp" . multi-vterm-project)
;;("<tab>" . vterm-send-tab)
))
;; Mecanografía
(use-package speed-type
:hook
(speed-type-mode . (lambda ()
(corfu-mode 0)
(display-line-numbers-mode 0)
(visual-line-mode 1)
(visual-fill-column-mode 1)))
:diminish
:config
(setq speed-type-gb-book-list '(66867 66866 66591 57303 15725 24536)
speed-type-min-chars 300
speed-type-max-chars 600))
;; Mostrar lo que se está presionando en pantalla
(use-package keypression
:config
(setq keypression-use-child-frame t
keypression-fade-out-delay 1.0
keypression-frame-justify 'keypression-left-justified
keypression-cast-command-name t
keypression-cast-command-name-format "%s %s"
keypression-combine-same-keystrokes t
keypression-x-offset 50
keypression-y-offset 100
keypression-font-face-attribute '(:width normal :height 180 :weight bold))
)
;; Un bonito y sencillo panel de inicio
(use-package dashboard
;; :init
;; (dashboard-setup-startup-hook)
:diminish dashboard-mode
:custom-face
(dashboard-heading ((t (:inherit (font-lock-string-face bold)))))
(dashboard-items-face ((t (:weight normal))))
(dashboard-no-items-face ((t (:weight normal))))
:config
(setq dashboard-set-file-icons t
dashboard-set-heading-icons t
dashboard-set-file-icons t
dashboard-week-agenda nil
dashboard-agenda-time-string-format "%Y-%m-%d %H:%M")
(setq dashboard-startup-banner
(expand-file-name "duck.svg" user-emacs-directory))
(setq dashboard-items '(
;; (recents . 10)
(agenda . 10)
))
)
;; Hydra - Permite crear conjuntos de atajos.
(use-package hydra
:defines posframe-border-width
:functions childframe-workable-p
:hook (emacs-lisp-mode . hydra-add-imenu)
:init
(when (childframe-workable-p)
(setq hydra-hint-display-type 'posframe)
(with-no-warnings
(defun hydra-set-posframe-show-params ()
"Set hydra-posframe style."
(setq hydra-posframe-show-params
`(:left-fringe 8
:right-fringe 8
:internal-border-width ,posframe-border-width
:internal-border-color ,(face-background 'posframe-border nil t)
:background-color ,(face-background 'tooltip nil t)
:foreground-color ,(face-foreground 'tooltip nil t)
:lines-truncate t
:poshandler posframe-poshandler-frame-center)))
(hydra-set-posframe-show-params)
(add-hook 'after-load-theme-hook #'hydra-set-posframe-show-params t))))
;; Pretty-Hydra - Su nombre ya indica lo que hace
(use-package pretty-hydra
:bind ("<f6>" . toggles-hydra/body)
:hook (emacs-lisp-mode . (lambda ()
(add-to-list
'imenu-generic-expression
'("Hydras"
"^.*(\\(pretty-hydra-define\\) \\([a-zA-Z-]+\\)"
2))))
:init
(cl-defun pretty-hydra-title (title &optional icon-type icon-name
&key face height v-adjust)
"Add an icon in the hydra title."
(let ((face (or face 'mode-line-emphasis))
(height (or height 1.2))
(v-adjust (or v-adjust 0.0)))
(concat
(when (and icon-type icon-name)
(let ((f (intern (format "nerd-icons-%s" icon-type))))
(when (fboundp f)
(concat
(apply f (list icon-name :face face :height height :v-adjust v-adjust))
" "))))
(propertize title 'face face))))
;; Global toggles
(with-no-warnings
(pretty-hydra-define toggles-hydra (:title (pretty-hydra-title "Toggles" 'faicon "nf-fa-toggle_on")
:color pink :quit-key ("q" "C-g"))
("Basic"
(("n" (cond ((fboundp 'display-line-numbers-mode)
(display-line-numbers-mode (if display-line-numbers-mode -1 1)))
((fboundp 'gblobal-linum-mode)
(global-linum-mode (if global-linum-mode -1 1))))
"line number"
:toggle (or (bound-and-true-p display-line-numbers-mode)
(bound-and-true-p global-linum-mode)))
("a" global-aggressive-indent-mode "aggressive indent" :toggle t)
("d" global-hungry-delete-mode "hungry delete" :toggle t)
("e" electric-pair-mode "electric pair" :toggle t)
("s" prettify-symbols-mode "pretty symbol" :toggle t)
("h" display-time-mode "time" :toggle t)
("i" indent-bars-mode "indent bars" :toggle t))
"Highlight"
(("l" global-hl-line-mode "line" :toggle t)
("p" show-paren-mode "brackets pairs" :toggle t)
("r" rainbow-delimiters-mode "rainbow brackets" :toggle t)
("w" global-display-fill-column-indicator-mode "fill column indicator" :toggle t)
("t" global-hl-todo-mode "todo" :toggle t))
"Program"
(("f" flymake-mode "flymake" :toggle t)
("c" flyspell-mode "spell check" :toggle t)
("u" subword-mode "subword" :toggle t)
("v" global-diff-hl-mode "gutter" :toggle t)
("V" diff-hl-flydiff-mode "live gutter" :toggle t)
("M" diff-hl-margin-mode "margin gutter" :toggle t)
("D" diff-hl-dired-mode "dired gutter" :toggle t))
))))
(provide 'init-utils)
;;; init-utils.el ends here