From 2066e827155ae2893097360024ffd975166a44ef Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 23 Jan 2021 00:23:05 +0800 Subject: 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. --- common.el | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'common.el') diff --git a/common.el b/common.el index 702124f..fa6f3fe 100644 --- a/common.el +++ b/common.el @@ -55,6 +55,110 @@ (t (other-window 1))))) +;;;###autoload +(defun durand-embark-scroll-down-or-go-to-completions (&optional arg) + "Scroll down; if this is not feasible, go to the completions buffer. +ARG means do this command ARG times." + (interactive "p") + (let ((original-point (point)) + (left (abs (forward-line arg))) + (completion-windows + (delq nil + (mapcar + (lambda (w) + (and (consp + (delq nil + (mapcar (lambda (name) + (string-match-p + name + (buffer-name (window-buffer w)))) + durand-completion-buffer-names))) + w)) + (window-list nil 'nomini)))) + (in-completion-p (consp + (delq nil + (mapcar + (lambda (name) + (string-match-p name (buffer-name))) + durand-completion-buffer-names))))) + (cond ((= (point) (point-max)) + (setq left (1+ left))) + ((get-text-property (point) 'field) + (goto-char original-point))) + (cond ((and (> left 0) + (consp completion-windows) + (not in-completion-p)) + (select-window (car completion-windows)) + (cond + ((> arg 0) + (goto-char (point-min)) + (cond + ((derived-mode-p 'completion-list-mode) + (next-completion 1)))) + ((< arg 0) + (goto-char (point-max)) + (cond + ((derived-mode-p 'completion-list-mode) + (next-completion -1))))))))) + +;;;###autoload +(defun durand-embark-scroll-up-or-go-to-completions (&optional arg) + "Scroll up; if this is not feasible, go to the completions buffer. +ARG means do this command ARG times." + (interactive "p") + (durand-embark-scroll-down-or-go-to-completions (- arg))) + +;;;###autoload +(defun durand-completion-scroll-down-or-go-to-minibuffer (&optional arg) + "Scroll down; if this is not feasible, go to the mini-buffer. +ARG means do this command ARG times." + (interactive "p") + (let ((original-point (point)) + (left (abs (forward-line arg))) + (minibuffer-active-p (active-minibuffer-window)) + (in-minibuffer-p (minibuffer-window-active-p (selected-window)))) + (cond ((= (point) (point-max)) + (setq left (1+ left))) + ((get-text-property (point) 'field) + (goto-char original-point))) + (cond ((and (> left 0) + minibuffer-active-p + (not in-minibuffer-p)) + (select-window (active-minibuffer-window)) + (cond + ((> arg 0) + (goto-char (point-min))) + ((< arg 0) + (goto-char (point-max)))))))) + +;;;###autoload +(defun durand-completion-scroll-up-or-go-to-minibuffer (&optional arg) + "Scroll up; if this is not feasible, go to the mini-buffer. +ARG means do this command ARG times." + (interactive "p") + (durand-completion-scroll-down-or-go-to-minibuffer (- arg))) + +;;; Don't ask me if I want to visit the file again. + +(require 'register) + +;;;###autoload +(cl-defmethod register-val-jump-to ((val cons) delete) + (cond + ((frame-configuration-p (car val)) + (set-frame-configuration (car val) (not delete)) + (goto-char (cadr val))) + ((window-configuration-p (car val)) + (set-window-configuration (car val)) + (goto-char (cadr val))) + ((eq (car val) 'file) + (find-file (cdr val))) + ((eq (car val) 'file-query) + (find-buffer-visiting (nth 1 val)) + (find-file (nth 1 val)) + (goto-char (nth 2 val))) + (t (cl-call-next-method val delete)))) + ;;; Intentionally disable some key-bindings. ;;;###autoload -- cgit v1.2.3-18-g5258