De-abbreviate package prefix, use nameless

This commit is contained in:
Kashish Sharma 2018-09-15 22:37:02 +05:30
parent 203161bac6
commit 8241b93068
2 changed files with 45 additions and 43 deletions

View File

@ -13,9 +13,8 @@ meets helm-mini's -
Plus, some improvements of its own - Plus, some improvements of its own -
1. If a recentf entry is already visited by a buffer, put the entry at 1. If a recentf entry is already visited by a buffer, put the entry at
the end of the (recentf?) candidates list. the end of the (recentf?) candidates list.
2. (planned) tweak `im/use-paths` to search and display 2. (planned) tweak `ido-mini-use-paths` to search and display not just
not just buffer names but also their file paths, wherever buffer names but also their file paths, wherever applicable.
applicable.
3. (planned) show documentation of functions from smex, akin to C-j in 3. (planned) show documentation of functions from smex, akin to C-j in
helm-M-x helm-M-x
@ -30,17 +29,16 @@ you write a function to change keybindings (you want to use
## TODO ## TODO
1. When called twice in succession, quit ido-mini 1. When called twice in succession, quit ido-mini
2. color the matched substring in the candidates? 2. color the matched substring in the candidates?
3. store only search terms in input history, not the selected 3. store only search terms in input history, not the selected buffer
buffer names/file paths names/file paths
4. Mimic exact C-j (`ido-select-text`) and RET behaviour 4. Mimic exact C-j (`ido-select-text`) and RET behaviour
(`ido-exit-minibuffer`) (`ido-exit-minibuffer`)
5. What if we search for files (perhaps only in user-specified 5. What if we search for files (perhaps only in user-specified
directories, when provided) when there are no matches in the directories, when provided) when there are no matches in the buffer
buffer list as well as in recentf? list as well as in recentf?
6. Add animated 6. Add animated
7. Add indicator if flx-ido-mode is enabled 7. Add indicator if flx-ido-mode is enabled
8. Stop using abbreviated prefixes 8. Add tests
9. Add tests
## Thanks ## Thanks
Thanks to wilfredh for the initial code that got me started - Thanks to wilfredh for the initial code that got me started -

View File

@ -6,43 +6,43 @@
(defgroup ido-mini nil (defgroup ido-mini nil
"Variables for ido-mini completion library.") "Variables for ido-mini completion library.")
(defface im/unsaved-buffer (defface ido-mini-unsaved-buffer
'((t (:foreground "orange"))) '((t (:foreground "orange")))
"Face used by `ido-mini' to indicate buffers which have "Face used by `ido-mini' to indicate buffers which have
been edited but not saved." been edited but not saved."
:group 'ido-mini) :group 'ido-mini)
(defface im/buffer-changed (defface ido-mini-buffer-changed
'((t (:foreground "red" :background "black"))) '((t (:foreground "red" :background "black")))
"Face used by `ido-mini' to indicate buffers whose file has "Face used by `ido-mini' to indicate buffers whose file has
been edited outside Emacs." been edited outside Emacs."
:group 'ido-mini) :group 'ido-mini)
(defface im/buffer-file-missing (defface ido-mini-buffer-file-missing
'((t (:foreground "Indianred2"))) '((t (:foreground "Indianred2")))
"Face used by `ido-mini' to indicate buffers whose file does "Face used by `ido-mini' to indicate buffers whose file does
not exist on disk." not exist on disk."
:group 'ido-mini) :group 'ido-mini)
(defcustom im/use-paths nil (defcustom ido-mini-use-paths nil
"If non-nil, display file paths of the associated files of "If non-nil, display file paths of the associated files of
buffers, where applicable (see function `im/add-paths'). buffers, where applicable (see function `ido-mini-add-paths').
Additionally, completion will search for buffer names as well as Additionally, completion will search for buffer names as well as
their file paths. their file paths.
Users may also find it useful to set this to nil and to enable Users may also find it useful to set this to nil and to enable
buffer uniquifying via `toggle-uniquify-buffer-names'.") buffer uniquifying via `toggle-uniquify-buffer-names'.")
(defcustom im/buffer-list-functions '(im/buffer-names (defcustom ido-mini-buffer-list-functions '(ido-mini-buffer-names
im/buffers-clean ido-mini-buffers-clean
im/buffers-bury-visible ido-mini-buffers-bury-visible
im/buffers-color) ido-mini-buffers-color)
"List of functions run sequentially over the output "List of functions run sequentially over the output
of `(buffer-list)', with the result of one being the input of the of `(buffer-list)', with the result of one being the input of the
next (using `->list'). Each should accept exactly one argument. next (using `->list'). Each should accept exactly one argument.
The resulting list is used by `ido-mini' for completion The resulting list is used by `ido-mini' for completion
candidates.") candidates.")
(defcustom im/recentf-list-functions '(im/recentf-bury-visited (defcustom ido-mini-recentf-list-functions '(ido-mini-recentf-bury-visited
im/recentf-color) ido-mini-recentf-color)
"List of functions run sequentially over `recentf-list', with "List of functions run sequentially over `recentf-list', with
the result of one being the input of the next (using `->list'). the result of one being the input of the next (using `->list').
Each should accept exactly one argument. The resulting list is Each should accept exactly one argument. The resulting list is
@ -58,18 +58,18 @@ return the result of (FN3 (FN2 (FN1 VAR)))"
(setq var (funcall fn var))) (setq var (funcall fn var)))
var) var)
(defun im/buffer-names (&optional buffer-list) (defun ido-mini-buffer-names (&optional buffer-list)
"Return a list of the name of all buffers returned "Return a list of the name of all buffers returned
by (buffer-list)." by (buffer-list)."
(let ((buffer-list (if buffer-list buffer-list (buffer-list)))) (let ((buffer-list (if buffer-list buffer-list (buffer-list))))
(-map 'buffer-name buffer-list))) (-map 'buffer-name buffer-list)))
(defun im/buffers-clean (buffer-names) (defun ido-mini-buffers-clean (buffer-names)
"Remove buffers whose names start with a space." "Remove buffers whose names start with a space."
(cl-flet ((leading-space-p (cl-flet ((leading-space-p
(el) (el)
(string-match-p "^ " el))) (string-match-p "^ " el)))
(-remove #'leading-space-p buffer-names))) (-remove #'leading-space-p buffer-names)))
(defun im/buffers-bury-visible (buffer-names) (defun ido-mini-buffers-bury-visible (buffer-names)
"Put visible buffers at the end of list, in reverse order of "Put visible buffers at the end of list, in reverse order of
appearance (e.g. (vb1 b1 vb2 b2 ...) becomes (b1 b2 ... vb2 appearance (e.g. (vb1 b1 vb2 b2 ...) becomes (b1 b2 ... vb2
vb1))" vb1))"
@ -81,21 +81,21 @@ by (buffer-list)."
(append (append
(-map 'car bufs-wo-wins) (-map 'car bufs-wo-wins)
(reverse (-map 'car bufs-with-wins))))) (reverse (-map 'car bufs-with-wins)))))
(defun im/buffers-color (buffer-names) (defun ido-mini-buffers-color (buffer-names)
(-map (-map
(lambda (buffer-name) (lambda (buffer-name)
(let ((buffer (get-buffer buffer-name))) (let ((buffer (get-buffer buffer-name)))
(cond (cond
((let ((bfn (buffer-file-name buffer))) ((let ((bfn (buffer-file-name buffer)))
(and bfn (not (file-exists-p bfn)))) (and bfn (not (file-exists-p bfn))))
(propertize buffer-name 'face 'im/buffer-file-missing)) (propertize buffer-name 'face 'ido-mini-buffer-file-missing))
;; buffers with unsaved files ;; buffers with unsaved files
((and (buffer-file-name buffer) ((and (buffer-file-name buffer)
(buffer-modified-p buffer)) (buffer-modified-p buffer))
(propertize buffer-name 'face 'im/unsaved-buffer)) (propertize buffer-name 'face 'ido-mini-unsaved-buffer))
;; buffer modified outside emacs ;; buffer modified outside emacs
((not (verify-visited-file-modtime buffer)) ((not (verify-visited-file-modtime buffer))
(propertize buffer-name 'face 'im/buffer-changed)) (propertize buffer-name 'face 'ido-mini-buffer-changed))
;; buffers with files ;; buffers with files
((buffer-file-name buffer) ((buffer-file-name buffer)
(propertize buffer-name 'face 'font-lock-type-face)) (propertize buffer-name 'face 'font-lock-type-face))
@ -109,65 +109,65 @@ by (buffer-list)."
(t buffer-name)))) (t buffer-name))))
buffer-names)) buffer-names))
(defun im/recentf-bury-visited (recentf) (defun ido-mini-recentf-bury-visited (recentf)
"Returns the contents of `recentf-list', with files being "Returns the contents of `recentf-list', with files being
visited by a buffer placed at the end of the list." visited by a buffer placed at the end of the list."
(append (append
(-remove #'get-file-buffer recentf) (-remove #'get-file-buffer recentf)
(-filter #'get-file-buffer recentf))) (-filter #'get-file-buffer recentf)))
(defun im/recentf-color (recentf) (defun ido-mini-recentf-color (recentf)
"Color recentf-list." "Color recentf-list."
(-map (lambda (el) (propertize el 'face 'ido-virtual)) (-map (lambda (el) (propertize el 'face 'ido-virtual))
recentf)) recentf))
(defun im/select-text (ido-choice) (defun ido-mini-select-text (ido-choice)
"Mimic superficial behaviour of `ido-select-text'. If there is "Mimic superficial behaviour of `ido-select-text'. If there is
an exact match for the search string, select it, else create a an exact match for the search string, select it, else create a
new buffer using the search string as the name.") new buffer using the search string as the name.")
(defun im/exit-minibuffer (ido-choice) (defun ido-mini-exit-minibuffer (ido-choice)
"Mimic superficial behaviour of `ido-exit-minibuffer'. If there "Mimic superficial behaviour of `ido-exit-minibuffer'. If there
is any match for the search string, select it, else print is any match for the search string, select it, else print
[Confirm] and after another RET, create a buffer using the search [Confirm] and after another RET, create a buffer using the search
string as the name.") string as the name.")
(defun im/save-search-string () (defun ido-mini-save-search-string ()
"Save search string from ido-completing-read into history.") "Save search string from ido-completing-read into history.")
;; (ido-completing-read "Buffer:" ;; (ido-completing-read "Buffer:"
;; (append (->list (buffer-list) ;; (append (->list (buffer-list)
;; im/buffer-list-functions) ;; ido-mini-buffer-list-functions)
;; (->list recentf-list ;; (->list recentf-list
;; im/recentf-list-functions))) ;; ido-mini-recentf-list-functions)))
;;;; IDO-MINI ---- ;;;; IDO-MINI ----
(defun ido-mini () (defun ido-mini ()
"A helm-mini replacement using Ido. Switch to a buffer or a "A helm-mini replacement using Ido. Switch to a buffer or a
recentf entry with ido. If `im/use-paths' is non-nil, recentf entry with ido. If `ido-mini-use-paths' is non-nil,
search for and display the whole file path instead of just the search for and display the whole file path instead of just the
file name. file name.
Using ido-vertical in conjunction may be beneficial. Using ido-vertical in conjunction may be beneficial.
It can be extended conveniently - see the variables It can be extended conveniently - see the variables
`im/buffer-list-functions' and `im/recentf-list-functions'. `ido-mini-buffer-list-functions' and `ido-mini-recentf-list-functions'.
Based off code from wilfredh - Based off code from wilfredh -
https://gist.github.com/Wilfred/31e8e0b24e3820c24850920444dd941d" https://gist.github.com/Wilfred/31e8e0b24e3820c24850920444dd941d"
(interactive) (interactive)
(let* (let*
((buffers-sorted (->list (buffer-list) ((buffers-sorted (->list (buffer-list)
;; '(im/buffer-names ;; '(ido-mini-buffer-names
;; im/buffers-clean ;; ido-mini-buffers-clean
;; im/buffers-bury-visible) ;; ido-mini-buffers-bury-visible)
im/buffer-list-functions ido-mini-buffer-list-functions
)) ))
(recentf-sorted (im/recentf-bury-visited recentf-list)) (recentf-sorted (ido-mini-recentf-bury-visited recentf-list))
(buffer-count (length buffers-sorted)) (buffer-count (length buffers-sorted))
(processed-buffers (->list (buffer-list) (processed-buffers (->list (buffer-list)
im/buffer-list-functions)) ido-mini-buffer-list-functions))
(processed-recentf (->list recentf-list (processed-recentf (->list recentf-list
im/recentf-list-functions)) ido-mini-recentf-list-functions))
(candidates (append processed-buffers (candidates (append processed-buffers
processed-recentf)) processed-recentf))
(ido-choice (completing-read "Switch to buffer: " (ido-choice (completing-read "Switch to buffer: "
@ -185,3 +185,7 @@ https://gist.github.com/Wilfred/31e8e0b24e3820c24850920444dd941d"
(switch-to-buffer (get-buffer-create ido-choice))))) (switch-to-buffer (get-buffer-create ido-choice)))))
(provide 'ido-mini) (provide 'ido-mini)
;; Local Variables:
;; nameless-current-name: "ido-mini"
;; End: