Files
confi-emacs-actual/configs/init-functions.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

138 lines
4.7 KiB
EmacsLisp

;;; init-functions.el --- Configuración de org-mode -*- lexical-binding: t -*-
;; Author: kj <webmaster@outcontrol.net>
;; URL: https://git.kj2.me/kj/confi-emacs-actual
;;; Commentary:
;; Aqui se encuentran funciones sueltas de Emacs.
;;; Code:
;; 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))
;; Comentar línea o región
(defun comment-or-uncomment-region-or-line ()
"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)
"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)))))
;; 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)))
;; 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)))) ;; <-- ¡Aquí está el cambio!
(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)))
;; Cambia entre ocultar o no la barra de título cuando está maximizado
(defun toggle-hide-title-bar()
"Toggle hide title bar when the frame is maximed."
(interactive)
(if (and (boundp 'title-bar-maximixed) title-bar-maximixed)
(progn
(remove-hook 'window-size-change-functions 'frame-hide-title-bar-when-maximized)
(setq title-bar-maximixed nil))
(progn
(add-hook 'window-size-change-functions 'frame-hide-title-bar-when-maximized)
(setq title-bar-maximixed t)))
)
;; Creando un hook para luego de que el theme ha cargado
(defvar after-load-theme-hook nil
"Hook run after a color theme is loaded using `load-theme'.")
(defadvice load-theme (after run-after-load-theme-hook activate)
"Run `after-load-theme-hook'."
(run-hooks 'after-load-theme-hook))
;; Devuelve si el archivo es muy grande o no\
(defun too-long-file-p ()
"Check whether the file is too long."
(or (> (buffer-size) 500000)
(and (fboundp 'buffer-line-statistics)
(> (car (buffer-line-statistics)) 10000))))
;; Renombrar el archivo actual
(defun rename-this-file (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(unless filename
(error "Buffer '%s' is not visiting a file!" name))
(progn
(when (file-exists-p filename)
(rename-file filename new-name 1))
(set-visited-file-name new-name)
(rename-buffer new-name))))
;; Copiar el nombre del archivo actual
(defun copy-file-name ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(buffer-file-name))))
(if filename
(progn
(kill-new filename)
(message "Copied '%s'" filename))
(warn "Current buffer is not attached to a file!"))))
;; Verifica si se puede levantar un childframe
(defun childframe-workable-p ()
"Whether childframe is workable."
(and (not noninteractive)
(not emacs-basic-display)
(or (display-graphic-p)
(featurep 'tty-child-frames))
(eq (frame-parameter (selected-frame) 'minibuffer) 't)))
(defun font-installed-p (font-name)
"Check if font with FONT-NAME is available."
(find-font (font-spec :name font-name)))
(provide 'init-functions)
;;; init-functions.el ends here.