Move sxiv code to its own file
This commit is contained in:
parent
8775ed5e4e
commit
7f55fd2017
|
@ -49,109 +49,6 @@
|
|||
:commands turn-on-launch-mode launch-files-dired
|
||||
:bind ("s-l" . launch-file))
|
||||
|
||||
(defun cp/dired-marked-files-p ()
|
||||
"Return t if there are marked files in the current Dired
|
||||
buffer. With no marked files, or if not in a Dired buffer, return
|
||||
nil."
|
||||
;; BUG - doesn't work as intended with non '*' markers (e.g. C or D)
|
||||
(interactive)
|
||||
(if (equal major-mode 'dired-mode)
|
||||
(if (save-excursion
|
||||
(goto-char (point-min))
|
||||
(re-search-forward dired-re-mark nil t))
|
||||
t
|
||||
nil)
|
||||
nil))
|
||||
|
||||
(defun cp/sxiv (&optional prefix)
|
||||
"Run sxiv(1), the Simple X Image Viewer.
|
||||
|
||||
By default, open all files in the current directory.
|
||||
|
||||
If run from a Dired buffer with marked files, open only those
|
||||
files. Files marked in sxiv will be marked in Dired.
|
||||
|
||||
With prefix argument, or when only provided directories, run
|
||||
recursively (-r).
|
||||
|
||||
If run from a text file containing one file name per line, open
|
||||
the files listed."
|
||||
(interactive "P")
|
||||
|
||||
;; TODO -
|
||||
;; 1. Let user edit options when called with null argument/two
|
||||
;; prefix arguments
|
||||
;; - use magit-popup for options! ❤
|
||||
;; 2. [-] when called with -o, parse the file names given by sxiv
|
||||
;; and mark them in Dired buffers (creating the Dired buffers if
|
||||
;; necessary)
|
||||
;; 3. When called with a text file at point, run sxiv with the files
|
||||
;; listed
|
||||
;; 4. When running with a lot of files, sxiv may take some time to
|
||||
;; start. Signal to the user that it is starting, and let them
|
||||
;; kill it if they want.
|
||||
;; 5. Create variable to hold default arguments
|
||||
;; 6. What should be the behavior when we open Dired-marked files,
|
||||
;; then mark files within sxiv?
|
||||
|
||||
;; BUG - doesn't work as intended with non '*' markers (e.g. C or D)
|
||||
|
||||
(let* ((paths (cond ((cp/dired-marked-files-p)
|
||||
(dired-get-marked-files))
|
||||
((equal major-mode 'text-mode)
|
||||
(--> (buffer-substring-no-properties (point-min)
|
||||
(point-max))
|
||||
(split-string it "\n")
|
||||
(-drop-last 1 it)))
|
||||
(t (directory-files default-directory))))
|
||||
(paths (--remove (or (equal it ".")
|
||||
(equal it ".."))
|
||||
paths))
|
||||
(recurse (or prefix
|
||||
(-every? #'file-directory-p paths)))
|
||||
;; remove directories if not running recursively
|
||||
(paths (->> (if recurse
|
||||
paths
|
||||
(seq-remove #'file-directory-p paths))
|
||||
(mapcar #'shell-quote-argument)
|
||||
(--reduce (concat acc " " it))))
|
||||
(recurse (if recurse "-r" ""))
|
||||
(proc (make-process :name "sxiv"
|
||||
:buffer "sxiv"
|
||||
:command
|
||||
(list shell-file-name
|
||||
shell-command-switch
|
||||
(concat "sxiv -afo "
|
||||
recurse
|
||||
" -- "
|
||||
paths))
|
||||
:connection-type 'pipe
|
||||
:stderr "sxiv-errors")))
|
||||
(setq cp--sxiv-directory default-directory)
|
||||
(set-process-filter proc #'cp-sxiv-filter)))
|
||||
|
||||
;; sxiv can also return relative paths to subdirectories if run
|
||||
;; recursively...how to handle that?
|
||||
(defun cp-sxiv-filter (process output)
|
||||
(find-file cp--sxiv-directory)
|
||||
(--> output
|
||||
(split-string it "\n")
|
||||
(-drop-last 1 it)
|
||||
(cp-dired-mark-files it)))
|
||||
|
||||
(defun cp-dired-mark-files (files)
|
||||
(interactive)
|
||||
(dired-mark-if
|
||||
(and (not (looking-at-p dired-re-dot))
|
||||
(not (eolp))
|
||||
(let ((fn (dired-get-filename t t)))
|
||||
(and fn (--find (equal fn it) files))))
|
||||
"file"))
|
||||
|
||||
(defvar cp--sxiv-directory nil
|
||||
"Directory `cp/sxiv' was called from.
|
||||
Used by `cp-sxiv-filter' to know where to mark files.")
|
||||
|
||||
(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)
|
||||
|
|
Loading…
Reference in New Issue