Last active
January 2, 2016 11:29
-
-
Save AlexBaranosky/8296589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; works, but only for already opened buffers | |
(defun projectile-cleanup-project-buffers () | |
(interactive) | |
(dolist (buffer (projectile-project-buffer-names)) | |
(condition-case nil | |
(with-current-buffer buffer | |
(esk-cleanup-buffer)) | |
(buffer-read-only nil)))) | |
;; doesn't work - intended to get it to run against all | |
;; project buffers even ones that aren't opened yet | |
(defun projectile-cleanup-project-files () | |
(interactive) | |
(dolist (filename (projectile-current-project-files)) | |
(condition-case nil | |
(with-current-buffer (find-file filename) | |
(esk-cleanup-buffer)) | |
(buffer-read-only nil)))) |
@bbatsov yeah I was thinking it'd be nice to have 2 functions:
- that calls a supplied fn for every buffer in the project
- that calls a supplied fn for every file in the project
@bbatsov so pumped to have learned enough elisp to have got this to work, thanks to your tip :)
(defun cleanup-file (filename)
(interactive "sFile: ")
(find-file filename)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(progn
(esk-cleanup-buffer)
(save-buffer)))))
(defun projectile-current-project-file-full-paths ()
(let ((root (projectile-project-root)))
(mapcar (lambda (filename)
(expand-file-name filename root))
(projectile-current-project-files))))
(defun projectile-cleanup-project-files ()
(interactive)
(dolist (filename (projectile-current-project-file-full-paths))
(cleanup-file filename)))
Yep, I think you're right. Open a ticket about the two functions in Projectile's issue tracker and I'll attend to them at some point.
Glad to hear my previous comments where helpful. Btw, without kill-buffer
in cleanup-file
you'll end up with a ton of open buffers in any bigger project.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
find-file
does not return a buffer object/name. It opens the file and a buffer and selects it. You can iterate through the files, runesk-cleanup-buffer
, save the buffer and kill it. I guess it might be useful if I added to projectile some command that abstracts the iteration, saving and killing away.