Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Add peep-dired-kill-buffers-without-window (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
asok committed Sep 1, 2014
1 parent c62781d commit d699fbf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Adjust the state name depending on an evil state you open dired in:
(add-hook 'peep-dired-hook 'evil-normalize-keymaps)
```

## Note about created buffers

For now the buffers opened when browsing a directory will not be killed until disabling the mode. If you want kill them manually you can run command `peep-dired-kill-buffers-without-window`.

## Contribution

Install [cask](https://github.com/rejeep/cask.el) if you haven't already, then:
Expand Down
11 changes: 11 additions & 0 deletions features/peep-dired.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ Feature: Looking up the contents of a file
And I run "peep-dired"
When I run "peep-dired-next-file"
Then the only visible windows are "peep-dired" and "peep-dired.el"

Scenario: Browsing dired buffer and peeping an already visited buffer
Given I open "peep-dired.el" file
And I open dired buffer in the root directory
And I place cursor on "features" entry
And I run "peep-dired"
When I run "peep-dired-next-file"
And I run "peep-dired-kill-buffers-without-window"
Then the peeped buffer "features" should be killed
And the only visible windows are "peep-dired" and "peep-dired.el"
When I run "peep-dired"
52 changes: 30 additions & 22 deletions features/step-definitions/peep-dired-steps.el
Original file line number Diff line number Diff line change
@@ -1,54 +1,62 @@
(Given "^I open dired buffer in the root directory$"
(lambda ()
(dired peep-dired-root-path)))
(dired peep-dired-root-path)))

(And "^I place cursor on \"\\(.+\\)\" entry$"
(lambda (filename)
(goto-char 0)
(while (not (string= (dired-get-filename nil t)
(expand-file-name filename)))
(forward-line 1))))
(expand-file-name filename)))
(forward-line 1))))

(When "^I run \"\\(.+\\)\"$"
(lambda (command )
(When "I start an action chain")
(When "I press \"M-x\"")
(And (s-lex-format "I type \"${command}\""))
(When "I press \"RET\"")
(And "I execute the action chain")))
(When "I start an action chain")
(When "I press \"M-x\"")
(And (s-lex-format "I type \"${command}\""))
(When "I press \"RET\"")
(And "I execute the action chain")))

(When "^I go down$"
(lambda ()
(forward-line 1)))
(forward-line 1)))

(When "^I go up$"
(lambda ()
(forward-line -1)))
(forward-line -1)))

(Then "^I should scroll down \"\\(.+\\)\" buffer in other window$"
(lambda (buffername)
(should (not (eq (window-start (get-buffer-window buffername)) 1)))))
(should (not (eq (window-start (get-buffer-window buffername)) 1)))))

(Then "^I should scroll up \"\\(.+\\)\" buffer in other window$"
(lambda (buffername)
(should (eq (window-start (get-buffer-window buffername)) 1))))
(should (eq (window-start (get-buffer-window buffername)) 1))))

(Then "^the peeped buffers should be killed$"
(lambda ()
(should (eq () peep-dired-peeped-buffers))))
(Then "^the peeped buffer \"\\(.+\\)\" should be killed$"
(lambda (buffername)
(should (not (member buffername (mapcar 'buffer-name (buffer-list)))))))

(Then "^the peeped buffer \"\\(.+\\)\" should not be killed$"
(lambda (buffername)
(should (member buffername (mapcar 'buffer-name (buffer-list))))))

(Then "the only visible windows are \"\\(.+\\)\" and \"\\(.+\\)\""
(lambda (dired-buffer peeped-buffer)
(should (equal
(list
(get-buffer-window dired-buffer)
(get-buffer-window peeped-buffer))
(window-list)))))
(should (equal
(list
(get-buffer-window dired-buffer)
(get-buffer-window peeped-buffer))
(window-list)))))

(Given "^I open \"\\(.+\\)\" file$"
(lambda (filename)
(find-file (expand-file-name filename peep-dired-root-path))))
(find-file (expand-file-name filename peep-dired-root-path))))

(Then "^the peeped buffers should be killed$"
(lambda ()
(should (eq () peep-dired-peeped-buffers))))

(Then "^key \"\\(.+\\)\" should be mapped to \"\\(.+\\)\"$"
(lambda (key command)
(should (equal (key-binding (kbd key)) (intern command)))))
(should (equal (key-binding (kbd key)) (intern command)))))
9 changes: 9 additions & 0 deletions peep-dired.el
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

;;; Code:

(require 'cl-macs)

(defvar peep-dired-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "<down>") 'peep-dired-next-file)
Expand Down Expand Up @@ -59,6 +61,13 @@
(dired-previous-line 1)
(peep-dired-display-file-other-window))

(defun peep-dired-kill-buffers-without-window ()
"Will kill all peep buffers that are not displayed in any window"
(interactive)
(cl-loop for buffer in peep-dired-peeped-buffers do
(unless (get-buffer-window buffer t)
(kill-buffer-if-not-modified buffer))))

(defun peep-dired-display-file-other-window ()
(let ((entry-name (dired-file-name-at-point)))
(add-to-list 'peep-dired-peeped-buffers
Expand Down

0 comments on commit d699fbf

Please sign in to comment.