X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=elisp.git;a=blobdiff_plain;f=selector.el;h=528d96dee378e177bd23b102224d848082643fd7;hp=17a5b2333f302fc31fa2a29189818766e1080d02;hb=HEAD;hpb=3771096a125c7cff7216ca61ce51b2cda5a7aca1 diff --git a/selector.el b/selector.el index 17a5b23..528d96d 100644 --- a/selector.el +++ b/selector.el @@ -21,8 +21,8 @@ ;; The selector/select function provides a simple interface for ;; selecting an object with on-the-fly pattern matching in a standard ;; buffer (i.e. not in the minibuffer). You can either use it in your -;; own functions or directly use selector/quick-pick-recent or -;; selector/quick-move-in-buffer. +;; own functions or directly use selector/quick-pick-recent, +;; selector/quick-move-in-buffer, or selector/switch-buffer ;; ;; For instance, you can add in your .emacs.el ;; @@ -63,11 +63,21 @@ Otherwise use the mode-line." :type 'bool :group 'selector) +(defcustom selector/add-to-file-name-history t + "If non-nil, file selected with selector/quick-pick-recent will be added to the mini-buffer filename history." + :type 'bool + :group 'selector) + (defcustom selector/mode-hook nil "Hook called at the end of the selector mode initialization." :type 'hook :group 'selector) +(defcustom selector/quick-pick-recent-hide-filter nil + "Regexp specifying which filenames should be hidden by `selector/quick-pick-recent'" + :type 'string + :group 'selector) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defface selector/selection @@ -330,52 +340,95 @@ There seems to be header-line refreshing problems with emacs21." (if (file-remote-p s) " " (propertize - (format-time-string "%a %b %e" (elt (file-attributes s) 5)) + (format-time-string "%b %a %e" (elt (file-attributes s) 5)) 'face 'selector/date)) - " -- " + ;; " -- " + + " " (if (string-match abbreviated-home-dir s) (concat (propertize (substring s 0 (match-end 0)) 'face 'selector/dim) (substring s (match-end 0))) s) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; (if (and (boundp 'selector/previous-filename) selector/previous-filename) + ;; (let ((l (abs (compare-strings + ;; selector/previous-filename nil nil + ;; filename nil nil)))) + ;; ;; (if (> l 0) (setq l + ;; (setq selector/previous-filename filename) + ;; (concat (propertize + ;; (substring s 0 l) 'face 'selector/dim) + ;; (substring s l)) + ;; ) + ;; filename + ;; ) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ) ) (defun selector/find-file (filename) + (if selector/add-to-file-name-history + (add-to-history 'file-name-history + (replace-regexp-in-string + abbreviated-home-dir "~/" filename) + ) + ) + + (find-file filename)) + +(defun selector/pick-file (filename) "Callback function for `selector/quick-pick-recent'. When called with a universal argument, allows the user to edit the filename." (interactive) (if current-prefix-arg - (find-file (read-file-name - "Find file: " - (file-name-directory filename) - nil - nil - (file-name-nondirectory filename))) - (find-file filename))) - -(defun selector/quick-pick-recent () + (selector/find-file (read-file-name + "Find file: " + (file-name-directory filename) + nil + nil + (file-name-nondirectory filename))) + (selector/find-file filename))) + +(defun selector/quick-pick-recent (universal) "Open a file picked in `recentf-list' with the dynamic -pattern-matching search implemented in `selector/select'. With a -prefix argument, allows to edit the filename after selection." - (interactive) +pattern-matching search implemented in `selector/select'. + +Without a prefix argument, hide files matching +`selector/quick-pick-recent-hide-filter'. + +With a prefix argument before the selection of the file per se, +permits to edit it before opening." + (interactive "P") (unless (and (boundp recentf-mode) recentf-mode) (error "recentf mode must be turned on")) - (selector/select - - (mapcar - (lambda (s) - (cons (selector/filename-to-string s) s)) - recentf-list) + (let ((l + (mapcar + (lambda (s) (cons (selector/filename-to-string s) s)) + (if (and (not universal) selector/quick-pick-recent-hide-filter) + (delq nil + (mapcar + (lambda (x) (and (not (string-match selector/quick-pick-recent-hide-filter x)) x)) + recentf-list) + ) + recentf-list + ) + ) + )) - 'selector/find-file - "*selector find-file*" - )) + (selector/select + l + 'selector/pick-file + "*selector find-file*" + )) + ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; To search in the current buffer