Refactor and add methods for filename insert and copy.

This commit is contained in:
kj
2025-09-04 10:11:44 -03:00
parent d50d5228cf
commit 0b6c2058ed
2 changed files with 19 additions and 5 deletions

View File

@ -102,7 +102,7 @@ If PROJECT is not specified, assume current project root."
(rename-buffer new-name))))
;; Copiar el nombre del archivo actual
(defun copy-file-name ()
(defun copy-filename ()
"Copy the current buffer file name to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
@ -114,6 +114,18 @@ If PROJECT is not specified, assume current project root."
(message "Copied '%s'" filename))
(warn "Current buffer is not attached to a file!"))))
(defun copy-basename ()
"Copy the current buffer basename to the clipboard."
(interactive)
(let ((filename (if (equal major-mode 'dired-mode)
default-directory
(file-name-nondirectory (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."
@ -127,12 +139,12 @@ If PROJECT is not specified, assume current project root."
"Check if font with FONT-NAME is available."
(find-font (font-spec :name font-name)))
(defun insert-full-filename ()
(defun insert-filename ()
"Insert the full path file name into the current buffer."
(interactive)
(insert (buffer-file-name)))
(defun insert-filename-only ()
(defun insert-basename ()
"Insert the filename (without path) into the current buffer."
(interactive)
(insert (file-name-nondirectory (buffer-file-name))))

View File

@ -35,8 +35,10 @@
(define-key global-map "\M-]" 'forward-paragraph)
;; Insertar nombre del archivo
(global-set-key (kbd "C-c ff") 'insert-full-filename)
(global-set-key (kbd "C-c fo") 'insert-filename-only)
(global-set-key (kbd "C-c ff") 'insert-filename)
(global-set-key (kbd "C-c fb") 'insert-basename)
(global-set-key (kbd "C-c fcf") 'copy-filename)
(global-set-key (kbd "C-c fcb") 'copy-basename)
;; Deactivar el abrir *messages* al cliquear en el minibuffer
(define-key minibuffer-inactive-mode-map [mouse-1] #'ignore)