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

View File

@ -6,43 +6,43 @@
(defgroup ido-mini nil
"Variables for ido-mini completion library.")
(defface im/unsaved-buffer
(defface ido-mini-unsaved-buffer
'((t (:foreground "orange")))
"Face used by `ido-mini' to indicate buffers which have
been edited but not saved."
:group 'ido-mini)
(defface im/buffer-changed
(defface ido-mini-buffer-changed
'((t (:foreground "red" :background "black")))
"Face used by `ido-mini' to indicate buffers whose file has
been edited outside Emacs."
:group 'ido-mini)
(defface im/buffer-file-missing
(defface ido-mini-buffer-file-missing
'((t (:foreground "Indianred2")))
"Face used by `ido-mini' to indicate buffers whose file does
not exist on disk."
: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
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
their file paths.
Users may also find it useful to set this to nil and to enable
buffer uniquifying via `toggle-uniquify-buffer-names'.")
(defcustom im/buffer-list-functions '(im/buffer-names
im/buffers-clean
im/buffers-bury-visible
im/buffers-color)
(defcustom ido-mini-buffer-list-functions '(ido-mini-buffer-names
ido-mini-buffers-clean
ido-mini-buffers-bury-visible
ido-mini-buffers-color)
"List of functions run sequentially over the output
of `(buffer-list)', with the result of one being the input of the
next (using `->list'). Each should accept exactly one argument.
The resulting list is used by `ido-mini' for completion
candidates.")
(defcustom im/recentf-list-functions '(im/recentf-bury-visited
im/recentf-color)
(defcustom ido-mini-recentf-list-functions '(ido-mini-recentf-bury-visited
ido-mini-recentf-color)
"List of functions run sequentially over `recentf-list', with
the result of one being the input of the next (using `->list').
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)))
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
by (buffer-list)."
(let ((buffer-list (if buffer-list buffer-list (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."
(cl-flet ((leading-space-p
(el)
(string-match-p "^ " el)))
(-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
appearance (e.g. (vb1 b1 vb2 b2 ...) becomes (b1 b2 ... vb2
vb1))"
@ -81,21 +81,21 @@ by (buffer-list)."
(append
(-map 'car bufs-wo-wins)
(reverse (-map 'car bufs-with-wins)))))
(defun im/buffers-color (buffer-names)
(defun ido-mini-buffers-color (buffer-names)
(-map
(lambda (buffer-name)
(let ((buffer (get-buffer buffer-name)))
(cond
((let ((bfn (buffer-file-name buffer)))
(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
((and (buffer-file-name buffer)
(buffer-modified-p buffer))
(propertize buffer-name 'face 'im/unsaved-buffer))
(propertize buffer-name 'face 'ido-mini-unsaved-buffer))
;; buffer modified outside emacs
((not (verify-visited-file-modtime buffer))
(propertize buffer-name 'face 'im/buffer-changed))
(propertize buffer-name 'face 'ido-mini-buffer-changed))
;; buffers with files
((buffer-file-name buffer)
(propertize buffer-name 'face 'font-lock-type-face))
@ -109,65 +109,65 @@ by (buffer-list)."
(t buffer-name))))
buffer-names))
(defun im/recentf-bury-visited (recentf)
(defun ido-mini-recentf-bury-visited (recentf)
"Returns the contents of `recentf-list', with files being
visited by a buffer placed at the end of the list."
(append
(-remove #'get-file-buffer recentf)
(-filter #'get-file-buffer recentf)))
(defun im/recentf-color (recentf)
(defun ido-mini-recentf-color (recentf)
"Color recentf-list."
(-map (lambda (el) (propertize el 'face 'ido-virtual))
recentf))
(defun im/select-text (ido-choice)
(defun ido-mini-select-text (ido-choice)
"Mimic superficial behaviour of `ido-select-text'. If there is
an exact match for the search string, select it, else create a
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
is any match for the search string, select it, else print
[Confirm] and after another RET, create a buffer using the search
string as the name.")
(defun im/save-search-string ()
(defun ido-mini-save-search-string ()
"Save search string from ido-completing-read into history.")
;; (ido-completing-read "Buffer:"
;; (append (->list (buffer-list)
;; im/buffer-list-functions)
;; ido-mini-buffer-list-functions)
;; (->list recentf-list
;; im/recentf-list-functions)))
;; ido-mini-recentf-list-functions)))
;;;; IDO-MINI ----
(defun ido-mini ()
"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
file name.
Using ido-vertical in conjunction may be beneficial.
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 -
https://gist.github.com/Wilfred/31e8e0b24e3820c24850920444dd941d"
(interactive)
(let*
((buffers-sorted (->list (buffer-list)
;; '(im/buffer-names
;; im/buffers-clean
;; im/buffers-bury-visible)
im/buffer-list-functions
;; '(ido-mini-buffer-names
;; ido-mini-buffers-clean
;; ido-mini-buffers-bury-visible)
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))
(processed-buffers (->list (buffer-list)
im/buffer-list-functions))
ido-mini-buffer-list-functions))
(processed-recentf (->list recentf-list
im/recentf-list-functions))
ido-mini-recentf-list-functions))
(candidates (append processed-buffers
processed-recentf))
(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)))))
(provide 'ido-mini)
;; Local Variables:
;; nameless-current-name: "ido-mini"
;; End: