Skip to content

Commit 98d27d3

Browse files
authored
Merge pull request #1296 from mychris/patch/directory-mode-kill-lines
Adds the command DIRECTORY-MODE-KILL-LINES.
2 parents c10c56f + aa74f6b commit 98d27d3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/ext/directory-mode.lisp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
(define-key *directory-mode-keymap* "r" 'directory-mode-rename-file)
6363
(define-key *directory-mode-keymap* "s" 'directory-mode-sort-files)
6464
(define-key *directory-mode-keymap* "+" 'make-directory)
65+
(define-key *directory-mode-keymap* "k" 'directory-mode-kill-lines)
6566

6667
(defun run-command (command)
6768
(when (consp command)
@@ -132,14 +133,18 @@
132133
(funcall function p)
133134
(unless (line-offset p 1) (return)))))
134135

135-
(defun marked-files (p)
136+
137+
(defun marked-lines (p)
136138
(with-point ((p p))
137-
(let ((pathnames '()))
139+
(let ((points '()))
138140
(iter-marks p
139141
(lambda (p)
140142
(when (get-mark p)
141-
(push (get-pathname p) pathnames))))
142-
(nreverse pathnames))))
143+
(push (copy-point p :temporary) points))))
144+
(nreverse points))))
145+
146+
(defun marked-files (p)
147+
(mapcar 'get-pathname (marked-lines p)))
143148

144149
(defun filter-marks (p function)
145150
(iter-marks p
@@ -566,6 +571,18 @@
566571
(let ((filename (file-namestring fullpath)))
567572
(search-filename-and-recenter (file-namestring filename)))))))
568573

574+
(define-command directory-mode-kill-lines () ()
575+
"Delete the marked lines from the directory-mode buffer.
576+
This does not delete the marked entries, but only remove them from the buffer."
577+
(with-buffer-read-only (current-buffer) nil
578+
(let ((*inhibit-read-only* t)
579+
(marked-lines (marked-lines (current-point))))
580+
(save-excursion
581+
;; Reverse the lines so killing is done from the end of the buffer
582+
(loop :for marked-line :in (nreverse marked-lines)
583+
:do (move-point (current-point) marked-line)
584+
(kill-whole-line))))))
585+
569586
(setf *find-directory-function* 'directory-buffer)
570587

571588
(defmethod execute :after ((mode directory-mode) command argument)

0 commit comments

Comments
 (0)