97 lines
3.6 KiB
EmacsLisp
97 lines
3.6 KiB
EmacsLisp
;;; packages.el --- dired-phundrak layer functions file for Spacemacs.
|
||
;;
|
||
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
|
||
;;
|
||
;; Author: Lucien Cartier-Tilet <phundrak@phundrak.fr>
|
||
;; URL: https://github.com/syl20bnr/spacemacs
|
||
;;
|
||
;; This file is not part of GNU Emacs.
|
||
;;
|
||
;;; License: GPLv3
|
||
|
||
; Custom functions ;;;;;;;;;;;;;;;;;;;;
|
||
|
||
(defun phundrak//open-marked-files (&optional @fname)
|
||
"Open all marked files in dired buffer as new Emacs buffers"
|
||
(interactive)
|
||
(let* (($file-list (if @fname
|
||
(progn (list @fname))
|
||
(if (string-equal major-mode "dired-mode")
|
||
(dired-get-marked-files)
|
||
(list (buffer-file-name))))))
|
||
(mapc (lambda ($fpath)
|
||
(find-file $fpath))
|
||
$file-list)))
|
||
|
||
(defun xah//open-in-external-app (&optional @fname)
|
||
"Open the current file or dired marked file in external app.
|
||
The app is chosen from your OS’ preference.
|
||
|
||
When called in emacs lisp, if @fname is given, open that.
|
||
|
||
URL `http://ergoemacs.org/emacs/emacs_dired_open_file_in_ext_apps.html'
|
||
Version 2019-01-18"
|
||
(interactive)
|
||
(let* (($file-list (if @fname
|
||
(progn (list @fname))
|
||
(if (string-equal major-mode "dired-mode")
|
||
(dired-get-marked-files)
|
||
(list (buffer-file-name)))))
|
||
($do-it-p (if (<= (length $file-list) 5)
|
||
t
|
||
(y-or-n-p "Open more than 5 files? "))))
|
||
(when $do-it-p
|
||
(mapc (lambda ($fpath)
|
||
(let ((process-connection-type nil))
|
||
(start-process "" nil "xdg-open" $fpath)))
|
||
$file-list))))
|
||
|
||
(defun xah//dired-sort ()
|
||
"Sort dired dir listing in different ways. Prompt for a choice.
|
||
URL `http://ergoemacs.org/emacs/dired_sort.html'
|
||
Version 2018-12-23, modified by Phundrak on 2019-08-06"
|
||
(interactive)
|
||
(let ($sort-by $arg)
|
||
(setq $sort-by (ido-completing-read "Sort by:" '( "name" "size" "date" "extension" )))
|
||
(cond
|
||
((equal $sort-by "name") (setq $arg "-ahl --group-directories-first"))
|
||
((equal $sort-by "date") (setq $arg "-ahl -t --group-directories-first"))
|
||
((equal $sort-by "size") (setq $arg "-ahl -S --group-directories-first"))
|
||
((equal $sort-by "extension") (setq $arg "-ahlD -X --group-directories-first"))
|
||
(t (error "logic error 09535" )))
|
||
(dired-sort-other $arg )))
|
||
|
||
(defun xah//dired-rename-space-to-underscore ()
|
||
"In dired, rename current or marked files by replacing space to
|
||
underscore _. If not in `dired', do nothing.
|
||
|
||
URL
|
||
`http://ergoemacs.org/emacs/elisp_dired_rename_space_to_underscore.html'
|
||
Version 2017-01-02"
|
||
(interactive)
|
||
(require 'dired-aux)
|
||
(if (equal major-mode 'dired-mode)
|
||
(progn
|
||
(mapc (lambda (x)
|
||
(when (string-match " " x )
|
||
(dired-rename-file x (replace-regexp-in-string " " "_" x) nil)))
|
||
(dired-get-marked-files ))
|
||
(revert-buffer))
|
||
(user-error "Not in dired.")))
|
||
|
||
(defun xah//dired-rename-space-to-hyphen ()
|
||
"In dired, rename current or marked files by replacing
|
||
space to hyphen -. If not in `dired', do nothing.
|
||
URL `http://ergoemacs.org/emacs/elisp_dired_rename_space_to_underscore.html'
|
||
Version 2016-12-22"
|
||
(interactive)
|
||
(require 'dired-aux)
|
||
(if (equal major-mode 'dired-mode)
|
||
(progn
|
||
(mapc (lambda (x)
|
||
(when (string-match " " x )
|
||
(dired-rename-file x (replace-regexp-in-string " " "_" x) nil)))
|
||
(dired-get-marked-files ))
|
||
(revert-buffer))
|
||
(user-error "Not in dired")))
|