diff options
author | JSDurand <mmemmew@gmail.com> | 2021-01-23 00:23:05 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2021-01-24 00:49:45 +0800 |
commit | 2066e827155ae2893097360024ffd975166a44ef (patch) | |
tree | e15bb118a4a0e622575847c05ef1dcfae30e58ef /completion-conf.el | |
parent | 588b6031e152b031be1dee04c7b38938ea7eb706 (diff) |
More custom functions and adjust for custom completion framework
* LICENSE: Add GPLv3.
* basic.el (durand-enlarge-window):
(durand-shrink-window):
(durand-enlarge-window-horizontally):
(durand-shrink-window-horizontally): Now I can easily maximize or
minimize windows.
* comb/orderless-conf.el ("orderless"): Now I try to use my own
completion framework.
* common.el (durand-embark-scroll-down-or-go-to-completions):
(durand-embark-scroll-up-or-go-to-completions):
(durand-completion-scroll-down-or-go-to-minibuffer):
(durand-completion-scroll-up-or-go-to-minibuffer): Move these
functions here since they do not belong to the completion framework in
my opinion.
(register):
(register-val-jump-to): Rewrite this method so that it does not have
to ask me if I want to open a file while jumping.
* completion-conf.el: My intended completion framework, which is still
work in progress.
* init.el ("comb/orderless-conf.el"):
("completion-conf.el"): Adjust things accordingly.
("durand-simple"): My custom functions for viewing and for opening
things.
* modeline.el (modeline-propertize):
(modeline-format-minor-modes):
(modeline-format-major-mode): Now the macro `modeline-propertize'
won't override properties that it does not intend to define. This has
the effect that the properties of the original constructs will go
through and have effect.
(modeline-format-main): Make sure the space has a positive length.
(modeline-format-buffer-name): Make sure the length does not exceed
half the width of the window.
Diffstat (limited to 'completion-conf.el')
-rw-r--r-- | completion-conf.el | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/completion-conf.el b/completion-conf.el new file mode 100644 index 0000000..e567eb7 --- /dev/null +++ b/completion-conf.el @@ -0,0 +1,93 @@ +;;; completion-conf.el --- My configurations for completions inside Emacs -*- lexical-binding: t; -*- + +;; Author: JSDurand <mmemmew@gmail.com> +;; Created: 2021-01-22 21:41:30 +;; Version: 0.0.1 +;; Keywords: matching + +;; This file is NOT part of GNU/Emacs. + +;; 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 +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Thsi file is my configurations of the built in completion framework +;; in Emacs. I intend to configure it to use my yet-to-come completion +;; style using suffix trees. + +;;; Code: + +(require 'minibuffer) +(require 'simple) + +(setq completion-styles '(substring partial-completion flex)) +(setq completion-category-defaults nil) +(setq completion-flex-nospace nil) +(setq completion-pcm-complete-word-inserts-delimiters t) +(setq completion-show-help nil) +(setq completion-ignore-case t) +(setq read-file-name-completion-ignore-case t) +(setq read-buffer-completion-ignore-case t) +(setq resize-mini-windows t) + +(define-key minibuffer-local-completion-map (vector 'down) #'durand-embark-scroll-down-or-go-to-completions) +(define-key minibuffer-local-completion-map (vector 'up) #'durand-embark-scroll-up-or-go-to-completions) +(define-key completion-list-mode-map (vector 'down) #'durand-completion-scroll-down-or-go-to-minibuffer) +(define-key completion-list-mode-map (vector 'up) #'durand-completion-scroll-up-or-go-to-minibuffer) + +;;;###autoload +(defvar durand-headlong-entered-minibuffer-p nil + "Whether or not we have entered minibuffer. + +This is used for determining if we shall exit the minibuffer when +there is only one candidate left.") + +;;;###autoload +(defun durand-headlong-minibuffer-setup-hook () + "The entry for the completion to be headlong. +Simply add this function to `minibuffer-setup-hook'." + ;; NOTE: When we run this function we first enter minibuffer, so we + ;; set a variable to its appropriate value. + (set 'durand-headlong-entered-minibuffer-p nil) + (add-hook 'post-command-hook 'durand-headlong-post-command-hook t) + (add-hook 'minibuffer-exit-hook 'durand-headlong-minibuffer-exit-hook)) + +;;;###autoload +(defun durand-headlong-post-command-hook () + "Exit the minibuffer if there is only one candidate left. + +In practice, when we first enter minibuffer, there is some +abnormal behaviour, so we only check when we have entered the +minibuffer as usual." + (let ((comps (completion-all-completions + (minibuffer-contents) + minibuffer-completion-table minibuffer-completion-predicate + (- (point) (minibuffer-prompt-end))))) + (cond + ((and durand-headlong-entered-minibuffer-p + comps + (not (consp (cdr comps)))) + (minibuffer-force-complete-and-exit)) + (t (set 'durand-headlong-entered-minibuffer-p t))))) + +;;;###autoload +(defun durand-headlong-minibuffer-exit-hook () + "Remove the hooks we added." + (remove-hook 'post-command-hook 'durand-headlong-post-command-hook) + (remove-hook 'minibuffer-setup-hook 'durand-headlong-minibuffer-setup-hook) + (remove-hook 'minibuffer-exit-hook 'durand-headlong-minibuffer-exit-hook)) + + +(provide 'completion-conf) +;;; completion-conf.el ends here |