confi-emacs-actual/configs/init-functions.el

86 lines
2.9 KiB
EmacsLisp
Raw Normal View History

2022-11-19 04:33:22 +01:00
;;; init-functions.el --- Configuración de org-mode -*- lexical-binding: t -*-
2022-05-05 08:08:01 +02:00
;; Author: kj <webmaster@outcontrol.net>
;; URL: https://git.kj2.me/kj/confi-emacs-actual
;;; Commentary:
2023-04-14 18:39:19 +02:00
;; Aqui se encuentran funciones sueltas de Emacs.
2022-05-05 08:08:01 +02:00
;;; Code:
2022-03-30 01:21:13 +02:00
;; Permite cambiar la transparencia de emacs.
(defun transparency (value)
"Change the transparency of the frame window, setting VALUE from 0 to 100."
(interactive "nTransparency Value 0 - 100 opaque:")
(set-frame-parameter nil 'alpha-background value))
;; Crear captura SVG del frame atual. Fuente: https://www.reddit.com/r/emacs/comments/idz35e/emacs_27_can_take_svg_screenshots_of_itself/
(defun screenshot-svg ()
"Save a screenshot of the current frame as an SVG image.
Saves to a temp file and puts the filename in the kill ring."
(interactive)
(let* ((filename (make-temp-file "Emacs" nil ".svg"))
(data (x-export-frames nil 'svg)))
(with-temp-file filename
(insert data))
(kill-new filename)
(message filename)))
;; Comentar línea o región
(defun comment-or-uncomment-region-or-line ()
2022-11-29 08:45:36 +01:00
"Comments or uncomments the region or the current line."
(interactive)
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)
;;(next-line) ;; saltar a la siguiente línea
))
;; Duplicar la línea actual
(defun duplicate-current-line (&optional n)
2022-11-29 08:45:36 +01:00
"Duplicate current line, make more than 1 copy given a numeric (N) argument."
(interactive "p")
(save-excursion
(let ((nb (or n 1))
(current-line (thing-at-point 'line)))
;; when on last line, insert a newline first
(when (or (= 1 (forward-line 1)) (eq (point) (point-max)))
(insert "\n"))
;; now insert as many time as requested
(while (> n 0)
(insert current-line)
(decf n)))))
2022-03-30 01:21:13 +02:00
;; Borrar espacios, tabs y saltos de línea innecesarios al guardar
(add-hook 'before-save-hook 'delete-trailing-whitespace)
2024-04-13 07:19:05 +02:00
;; Mostrar y ocultar el diff de la línea de git-gutter
(defun git-gutter:toggle-popup-hunk ()
"Toggle 'git-gutter' hunk window."
(interactive)
(if (and (get-buffer "*git-gutter:diff*") (window-live-p (git-gutter:popup-buffer-window)))
(delete-window (git-gutter:popup-buffer-window))
(git-gutter:popup-hunk)))
2024-04-18 11:32:51 +02:00
;; Obtener el nombre del proyecto desde project.el
(defun kj/project-name (&optional project)
"Return the name for PROJECT.
If PROJECT is not specified, assume current project root."
(when-let (root (or project (kj/project-root)))
(file-name-nondirectory
(directory-file-name
(file-name-directory root)))))
;; Obtener la raíz del proyecto desde project.el
(defun kj/project-root ()
"Return the current project root."
(when-let (project (project-current))
(project-root project)))
2022-11-19 04:33:22 +01:00
(provide 'init-functions)
;;; init-functions.el ends here.