;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; http://user.it.uu.se/~embe8573/emacs-init/files-my.el ;;; https://dataswamp.org/~incal/emacs-init/files-my.el (require 'find-command) (require 'sudo-user-path) (require 'tramp) (defun delete-current-file () (interactive) (let*((file (buffer-file-name)) (prompt (format "delete %s on disk? " file)) ) (when (yes-or-no-p prompt) (kill-buffer) (delete-file file) ))) (defalias 'delete-this-file #'delete-current-file) (defun make-executable () (interactive) (shell-command (format "chmod +x %s" buffer-file-name)) ) (defun message-permissions () (interactive) (message "%s" (tramp-file-mode-from-int (file-modes buffer-file-name))) ) (defun find-file-at-line (&optional other-window) (interactive "P") (let ((possible-filename (thing-at-point 'filename t)) ; NO-PROPERTIES (find-fun (if other-window #'find-file-other-window #'find-file)) ) (if (and possible-filename (file-exists-p possible-filename)) (apply find-fun (list possible-filename)) (forward-char 1) (find-file-at-line) ))) (defun find-zsh-command-file-file () "`find-file' the file in the zsh env COMMAND_FILE. It is set in ~/.zshenv." (interactive) (let*((file (file-to-string (getenv "COMMAND_FILE"))) (search-string (file-to-string (getenv "COMMAND_STR_FILE"))) (search-string-fun-syntax (format "%s ()" search-string)) ) (when (file-exists-p file) (find-file file) (let ((start (point))) (goto-char 0) (if (search-forward search-string-fun-syntax nil t) (beginning-of-line-at-top) (goto-char start) ))))) (provide 'files-my)