Start at the image at point

This commit is contained in:
contrapunctus 2020-01-14 01:56:53 +05:30
parent cddff79c47
commit 8802975498
3 changed files with 49 additions and 32 deletions

View File

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
* Open sxiv at the image at point
## [0.2.0] - 2020-01-13
### Added
* `sxiv-arguments` to hold argument list

View File

@ -17,11 +17,11 @@ Run it from a text file containing one file name per line to open the listed fil
## TODO
1. [x] Create user-customizable variable to hold default arguments
2. Start sxiv on the file at point (using `-n ...`)
2. [x] Start sxiv on the file at point (using `-n ...`)
3. [x] Let user specify paths to be excluded.
4. Mark files in subdirectories if run recursively (by inserting the subdirectory into the current buffer)
5. Let user edit options (ideally with transient.el) when called with null argument/two prefix arguments
6. 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.
4. [ ] Mark files in subdirectories if run recursively (by inserting the subdirectory into the current buffer)
5. [ ] Let user edit options (ideally with transient.el) when called with null argument/two prefix arguments
6. [ ] 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.
7. What should be the behavior when we open Dired-marked files, then mark files within sxiv?
## Limitations

69
sxiv.el
View File

@ -76,36 +76,49 @@ run recursively (-r).
If run from a text file containing one file name per line, open
the files listed."
(interactive "P")
(let* ((paths (cond ((sxiv-dired-marked-files-p)
(dired-get-marked-files))
((derived-mode-p 'text-mode)
(--> (buffer-substring-no-properties (point-min)
(point-max))
(split-string it "\n")))
(t (directory-files default-directory))))
(paths (--remove (or (equal it ".")
(equal it "..")
(-find (lambda (exclude)
(string-match-p exclude it))
sxiv-exclude-strings))
paths))
(let* ((path-at-point (dired-file-name-at-point))
(fn-at-point (when path-at-point
(file-relative-name path-at-point)))
(paths (cond ((sxiv-dired-marked-files-p)
(dired-get-marked-files))
((derived-mode-p 'text-mode)
(--> (buffer-substring-no-properties (point-min)
(point-max))
(split-string it "\n")))
(t (directory-files default-directory))))
(paths (--remove (or (equal it ".")
(equal it "..")
;; Currently, this takes effect even
;; when running from a text
;; file...should that be the case?
(-find (lambda (exclude)
(string-match-p exclude it))
sxiv-exclude-strings))
paths))
;; recurse with prefix arg, or if every path is a directory
(recurse (or prefix
(-every? #'file-directory-p 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)))
(recurse (if recurse "-r" ""))
(proc (make-process :name "sxiv"
:buffer "sxiv"
:command
(append '("sxiv")
sxiv-arguments
`(,recurse "--")
paths)
:connection-type 'pipe
:stderr "sxiv-errors")))
(paths (if recurse
paths
(seq-remove #'file-directory-p paths)))
(fn-at-point-index (when fn-at-point
(->> paths
(--find-index (equal fn-at-point it))
(1+)
(number-to-string))))
(recurse (if recurse "-r" ""))
(proc (make-process :name "sxiv"
:buffer "sxiv"
:command
(append '("sxiv")
sxiv-arguments
(when fn-at-point-index
(list "-n" fn-at-point-index))
(list recurse "--")
paths)
:connection-type 'pipe
:stderr "sxiv-errors")))
(setq sxiv--directory default-directory)
(set-process-filter proc #'sxiv-filter)))