204 lines
6.8 KiB
EmacsLisp
204 lines
6.8 KiB
EmacsLisp
;; -*- lexical-bindiing: t; -*-
|
|
|
|
;; TODO - function which deletes buffers (esp. files and dired buffers) above a certain size. Then, set that to a timer.
|
|
|
|
;;;; File management
|
|
|
|
(add-to-list 'load-path "~/.emacs.d/elisp-git/dired-toggle-sudo/")
|
|
(add-to-list 'load-path "~/.emacs.d/elisp-git/project-explorer/")
|
|
|
|
(use-package dired
|
|
:init (add-hook 'dired-mode-hook 'turn-on-launch-mode)
|
|
:config
|
|
(setq dired-listing-switches
|
|
;; by date
|
|
;; "-cgGhlt --group-directories-first --time-style=long-iso"
|
|
;; by name
|
|
"-Achl --group-directories-first --time-style=long-iso"
|
|
;; no -h
|
|
;; "-cgGl --group-directories-first --time-style=long-iso"
|
|
|
|
;; by date, no --group-directories-first
|
|
;; "-cgGhlt --time-style=long-iso"
|
|
)
|
|
:bind
|
|
(:map dired-mode-map
|
|
("W" . wdired-change-to-wdired-mode)
|
|
("e" . #'cp/dired-do-ediff)
|
|
;; after learning that this copies whole paths with null
|
|
;; argument, this became a whole lot more useful
|
|
("C-w" . dired-copy-filename-as-kill)
|
|
("C-c C-f" . cp/corresponding-text-file)
|
|
("h" . dired-hide-dotfiles-mode)
|
|
("H" . dired-omit-mode)
|
|
([mouse-2] . cp/dired-launch-or-open)
|
|
("C-j" . launch-files-dired)
|
|
("j" . launch-files-dired)
|
|
("M-s r" . dired-do-query-replace-regexp)
|
|
("M-s s" . dired-do-isearch-regexp)
|
|
("P" . emms-play-dired)
|
|
("X" . dired-do-flagged-delete)
|
|
("M-n" . dired-next-marked-file)
|
|
("M-p" . dired-prev-marked-file))
|
|
:hook
|
|
(dired-mode . (lambda () (dired-hide-details-mode t))))
|
|
|
|
(use-package dired-async
|
|
:init (dired-async-mode 1))
|
|
|
|
(use-package dired-x
|
|
:commands dired-jump
|
|
:bind
|
|
("C-x C-d" . dired-jump))
|
|
|
|
;; TODO - make launch-file suggest the path at point by default
|
|
(use-package launch
|
|
:commands turn-on-launch-mode launch-files-dired
|
|
:bind ("s-l" . launch-file))
|
|
|
|
(defun cp/open-random-file (&optional find-args dir cmd)
|
|
"Open a random file in DIR, prompting the user for it if not supplied."
|
|
(interactive)
|
|
(let* ((find-args (if find-args find-args " -type f "))
|
|
(dir (if dir dir
|
|
(read-directory-name "Directory: "
|
|
(if file-name-history
|
|
(car file-name-history)
|
|
default-directory)
|
|
nil t)))
|
|
(file-name (--> (expand-file-name dir)
|
|
(concat "find " "\"" it "\" "
|
|
find-args " | shuf | sed 1q")
|
|
(shell-command-to-string it)
|
|
(replace-regexp-in-string "\n" "" it))))
|
|
(if cmd
|
|
(async-shell-command (concat cmd " \"" file-name "\""))
|
|
(find-file file-name))))
|
|
|
|
(with-eval-after-load 'project-explorer
|
|
(global-set-key (kbd "<f5> e") 'project-explorer-toggle))
|
|
|
|
(use-package dired-hide-dotfiles
|
|
:hook (dired-mode . (lambda () (dired-hide-dotfiles-mode))))
|
|
|
|
;; (require 'sudo-edit)
|
|
|
|
(defun cp/dired-do-ediff (&optional format)
|
|
"Ediff (first two or three) marked files."
|
|
(interactive)
|
|
(let* ((files (dired-get-marked-files t))
|
|
(file-1 (car files))
|
|
(files-dir default-directory))
|
|
;; 2018-04-08T11:31:20+0530 TODO - if there is only one marked
|
|
;; file, check the other window for a marked file and ediff with
|
|
;; that.
|
|
(case (length files)
|
|
(1 (progn
|
|
(other-window 1)
|
|
(let ((files2 (dired-get-marked-files t))
|
|
(files2-dir default-directory))
|
|
(if files2
|
|
(ediff (expand-file-name
|
|
(concat files-dir (car files)))
|
|
(expand-file-name
|
|
(concat files2-dir (car files2))))))))
|
|
(2 (ediff file-1
|
|
(cadr files)))
|
|
(t (ediff3 file-1
|
|
(cadr files)
|
|
(elt files 2))))))
|
|
|
|
(defun cp/change-all-units ()
|
|
"for fdupes output"
|
|
(interactive)
|
|
(while (re-search-forward "^[0-9]+" nil t)
|
|
(shell-command-on-region (point-at-bol) (point) "numfmt --to=iec-i --suffix=B" nil t)
|
|
(forward-word)
|
|
(delete-region (point) (progn (forward-word) (point)))))
|
|
|
|
(defun cp/launch-file-archive ()
|
|
(interactive)
|
|
(launch-file
|
|
(concat
|
|
default-directory
|
|
(aref (archive-get-descr) 0))))
|
|
|
|
;; (define-key archive-mode-map (kbd "j") 'cp/launch-file-archive)
|
|
|
|
;; 2018-02-28T21:00:57+0530
|
|
(defun cp/corresponding-text-file ()
|
|
(interactive)
|
|
(save-excursion
|
|
(end-of-line)
|
|
(if (derived-mode-p 'dired-mode)
|
|
;; 2018-08-05T02:01:26+0530 - support directories too
|
|
(let* ((file-or-dir (dired-file-name-at-point))
|
|
(file (if (file-directory-p file-or-dir)
|
|
(replace-regexp-in-string "/$" "" file-or-dir)
|
|
file-or-dir)))
|
|
(find-file (concat file ".txt"))))))
|
|
|
|
;; 2018-07-09T23:22:17+0530
|
|
;; a little buggy wrt clicks
|
|
(defun cp/dired-launch-or-open (event)
|
|
(interactive "e")
|
|
;; if point is on a folder, open it with dired
|
|
;; otherwise, call launch-files-dired
|
|
(if (directory-name-p (dired-file-name-at-point))
|
|
(dired-find-file)
|
|
(launch-files-dired nil (dired-get-marked-files))))
|
|
|
|
(defun contrapunctus-delete-file-at-point (&optional prefix)
|
|
(interactive "P")
|
|
(let ((file (buffer-substring (point-at-bol)
|
|
(point-at-eol))))
|
|
(if (file-exists-p file)
|
|
(progn
|
|
(delete-file file)
|
|
(if prefix
|
|
;; delete current line
|
|
(delete-region (point-at-bol)
|
|
(1+ (point-at-eol)))
|
|
;; delete current paragraph
|
|
(mark-paragraph)
|
|
(delete-active-region)
|
|
(forward-line 2))
|
|
(message "Deleted %s" file))
|
|
(error "File %s does not exist!" file))))
|
|
|
|
(defun contrapunctus-file-at-point-exists-p ()
|
|
(interactive)
|
|
(let ((file (buffer-substring (point-at-bol)
|
|
(point-at-eol))))
|
|
(if (and (not (string-empty-p file))
|
|
(file-exists-p file))
|
|
(message "%s" t)
|
|
(error "File %S does not exist!" file))))
|
|
|
|
(use-package sxiv
|
|
:bind (("<f2> s" . sxiv)
|
|
:map dired-mode-map
|
|
("I" . sxiv)))
|
|
|
|
(use-package contrasync
|
|
:load-path "~/.emacs.d/contrapunctus/contrasync/"
|
|
:config
|
|
(setq contrasync-disk-path "/media/anon/kash-sg-2tb/"
|
|
contrasync-source-paths
|
|
`("~/.emacs.d/"
|
|
"~/1-music-notation/"
|
|
"~/Documents/"
|
|
"~/.config/"
|
|
"~/.local/"
|
|
("~/phone/Nokia 6.1/" ,contrasync-disk-path "phone/Nokia 6.1/"))))
|
|
|
|
(use-package peep-dired
|
|
:disabled
|
|
;; ;; didn't work too well 🤔
|
|
;; :config
|
|
;; (setq peep-dired-cleanup-eagerly t)
|
|
:hook
|
|
(dired-mode . peep-dired))
|
|
|
|
(provide 'cp-fm)
|