Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay mode hooks when opening unvisited files #7

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions noccur.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Keywords: convenience
;; Version: 0.2
;; Package: noccur
;; Package-Requires: ()
;; Package-Requires: ((emacs "24.4"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -55,7 +55,15 @@ For performance reasons, files are filtered using 'find' or 'git
ls-files' and 'grep'."
(interactive (occur-read-primary-args))
(let* ((default-directory (or directory-to-search (read-directory-name "Search in directory: ")))
(files (mapcar #'find-file-noselect
(files (mapcar (lambda (x)
(or (find-buffer-visiting x)
;; Delay mode hooks when opening unvisited files
(with-current-buffer (create-file-buffer x)
(insert-file-contents x)
(setq buffer-file-name x)
(delay-mode-hooks (set-auto-mode))
(set-buffer-modified-p nil)
(current-buffer))))
(noccur--find-files regexp))))
(multi-occur files regexp nlines)))

Expand All @@ -69,7 +77,8 @@ ls-files' and 'grep'."
(command (format "%s | xargs -0 grep -l \"%s\""
listing-command
regexp)))
(split-string (shell-command-to-string command) "\n")))
(cl-remove-if #'string-empty-p
(split-string (shell-command-to-string command) "\n"))))

(provide 'noccur)
;;; noccur.el ends here