From 9ea09a109a9aa23b871677c8ca87b25877e5054c Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Mon, 17 Oct 2022 02:02:30 +0900 Subject: [PATCH 01/24] Fix to follow up pophint updated --- owdriver.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index 8f78e72..70a2a6c 100644 --- a/owdriver.el +++ b/owdriver.el @@ -233,7 +233,8 @@ (featurep 'pophint) (boundp 'pophint--next-window-source) (>= (loop for w in (window-list) count (funcall is-nextable-window w)) 2))) - (setq nextwnd (pophint:do :source pophint--next-window-source :allwindow t)) + (setq nextwnd (when-let ((hint (pophint:do :source pophint--next-window-source :allwindow t))) + (pophint:hint-window hint))) (while (and (> move-amount 0) (not (eq nextwnd currwnd))) (other-window (if reverse -1 1)) From 6c1e6a59719df2548fe6150e87b89addbe8f7aa4 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 23 Oct 2022 20:58:42 +0900 Subject: [PATCH 02/24] Quit including third party library --- owdriver.el | 6 ------ 1 file changed, 6 deletions(-) diff --git a/owdriver.el b/owdriver.el index 70a2a6c..b617c99 100644 --- a/owdriver.el +++ b/owdriver.el @@ -103,8 +103,6 @@ (require 'smartrep) (require 'log4e) (require 'yaxception) -(require 'inertial-scroll nil t) -(require 'pophint nil t) (defgroup owdriver nil "Quickly perform various actions on other windows." @@ -364,10 +362,6 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (owdriver-define-command isearch-backward t (isearch-backward)) (owdriver-define-command set-mark-command t) (owdriver-define-command kill-ring-save t (call-interactively 'kill-ring-save) (deactivate-mark)) - ;; Third party command - (owdriver-define-command pophint:do t (pophint:do :not-switch-window t)) - (owdriver-define-command inertias-up t) - (owdriver-define-command inertias-down t) ;; Patch for Emacs 26.1 (when (>= emacs-major-version 26) From dc4c33e6bc39ff7903683f892daa73d662f88f1a Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 23 Oct 2022 21:14:23 +0900 Subject: [PATCH 03/24] Fix to use cl-lib --- owdriver.el | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/owdriver.el b/owdriver.el index b617c99..a9b2f73 100644 --- a/owdriver.el +++ b/owdriver.el @@ -99,7 +99,7 @@ ;; Enjoy!!! -(eval-when-compile (require 'cl)) +(eval-when-compile (require 'cl-lib)) (require 'smartrep) (require 'log4e) (require 'yaxception) @@ -137,7 +137,7 @@ ;;;;;;;;;;;;; ;; Utility -(defun* owdriver--show-message (msg &rest args) +(cl-defun owdriver--show-message (msg &rest args) (apply 'message (concat "[OWDRIVER] " msg) args) nil) @@ -167,24 +167,24 @@ (defun owdriver--get-binding-keys (cmd) (owdriver--trace "start get binding keys : %s" cmd) - (loop for b in (where-is-internal cmd global-map) - for bindkey = (or (ignore-errors (key-description b)) - "") - if (and (not (string= bindkey "")) - (not (string-match "\\`" bindkey)) - (not (string-match "\\`<[^>]*mouse[^>]*>" bindkey))) - collect (progn (owdriver--trace "found binding : %s" bindkey) - bindkey))) + (cl-loop for b in (where-is-internal cmd global-map) + for bindkey = (or (ignore-errors (key-description b)) + "") + if (and (not (string= bindkey "")) + (not (string-match "\\`" bindkey)) + (not (string-match "\\`<[^>]*mouse[^>]*>" bindkey))) + collect (progn (owdriver--trace "found binding : %s" bindkey) + bindkey))) (defun owdriver--get-keybind (cmd) (owdriver--trace "start get keybind : %s" cmd) - (loop with ret = nil - for k in (owdriver--get-binding-keys cmd) - if (or (not ret) - (< (length k) (length ret))) - do (setq ret k) - finally return (progn (owdriver--trace "got keybind : %s" ret) - ret))) + (cl-loop with ret = nil + for k in (owdriver--get-binding-keys cmd) + if (or (not ret) + (< (length k) (length ret))) + do (setq ret k) + finally return (progn (owdriver--trace "got keybind : %s" ret) + ret))) ;;;;;;;;;; @@ -230,7 +230,7 @@ (if (and (and owdriver-next-window-prefer-pophint (featurep 'pophint) (boundp 'pophint--next-window-source) - (>= (loop for w in (window-list) count (funcall is-nextable-window w)) 2))) + (>= (cl-loop for w in (window-list) count (funcall is-nextable-window w)) 2))) (setq nextwnd (when-let ((hint (pophint:do :source pophint--next-window-source :allwindow t))) (pophint:hint-window hint))) (while (and (> move-amount 0) @@ -239,7 +239,7 @@ (setq nextwnd (get-buffer-window)) (owdriver--trace "selected next window : %s" nextwnd) (when (funcall is-nextable-window nextwnd) - (decf move-amount) + (cl-decf move-amount) (owdriver--trace "decremented move-amount[%s]" move-amount)))) ;; Blink target window after move (when (not (eq nextwnd currwnd)) From 0232a0168d4d622a45aa7b78b17af2c274a5bf2e Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 23 Oct 2022 21:16:01 +0900 Subject: [PATCH 04/24] Quit to define to call owdriver-quit --- owdriver.el | 3 --- 1 file changed, 3 deletions(-) diff --git a/owdriver.el b/owdriver.el index a9b2f73..a55996b 100644 --- a/owdriver.el +++ b/owdriver.el @@ -338,10 +338,7 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (owdriver-add-keymap "C-o" 'owdriver-next-window) (owdriver-add-keymap "C-S-o" 'owdriver-previous-window) (owdriver-add-keymap "" 'owdriver-focus-window) - (owdriver-add-keymap "" 'owdriver-quit) - (owdriver-add-keymap "C-q" 'owdriver-quit) ;; Basic command - (owdriver-define-command newline t (owdriver-quit)) (owdriver-define-command scroll-up t) (owdriver-define-command scroll-up-command t) (owdriver-define-command scroll-down t) From 1be2b5daee0f28cbd8b5bffa7b4a7a1a04e468d9 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Mon, 24 Oct 2022 01:12:58 +0900 Subject: [PATCH 05/24] Change concept from using smartrep to using just window-configuration and marker --- owdriver.el | 99 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/owdriver.el b/owdriver.el index a55996b..57b8bbd 100644 --- a/owdriver.el +++ b/owdriver.el @@ -6,7 +6,7 @@ ;; Keywords: convenience ;; URL: https://github.com/aki2o/owdriver ;; Version: 0.2.0 -;; Package-Requires: ((smartrep "0.0.3") (log4e "0.2.0") (yaxception "0.2.0")) +;; Package-Requires: ((log4e "0.2.0") (yaxception "0.2.0")) ;; 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 @@ -30,7 +30,6 @@ ;;; Dependency: ;; -;; - smartrep.el ( see ) ;; - yaxception.el ( see ) ;; - log4e.el ( see ) @@ -91,7 +90,6 @@ ;;; Tested On: ;; ;; - Emacs ... GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 Version 10.10.5 (Build 14F2511)) of 2018-05-31 -;; - smartrep.el ... Version 0.0.3 ;; - yaxception.el ... Version 0.2.0 ;; - log4e.el ... Version 0.2.0 @@ -100,7 +98,6 @@ (eval-when-compile (require 'cl-lib)) -(require 'smartrep) (require 'log4e) (require 'yaxception) @@ -131,7 +128,6 @@ (defvar owdriver--window nil "Current window drived by the command of `owdriver-mode-map'.") (defvar owdriver--move-window-amount nil) -(defvar owdriver--keymap-alist nil) ;;;;;;;;;;;;; @@ -201,12 +197,50 @@ :keymap owdriver-mode-map :global t :group 'owdriver - (smartrep-define-key owdriver-mode-map owdriver-prefix-key owdriver--keymap-alist)) + (if owdriver-mode + (add-hook 'pre-command-hook 'owdriver--cleanup) + (remove-hook 'pre-command-hook 'owdriver--cleanup))) ;;;;;;;;;;;;;;;;;; ;; User Command +(defvar owdriver--window-configuration nil) +(defvar owdriver--marker nil) +(defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) +(defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) +(defvar owdriver-keep-driving-command-regexp (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes))))) +(defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) + +(defun owdriver--keep-driving-with-default (command) + (or (memq command owdriver-keep-driving-commands) + (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) + +(defun owdriver--cleanup () + (when (and owdriver-mode + (not (funcall owdriver-keep-driving-function this-command))) + (message "OWSTOP! %s" this-command) + (when owdriver--window-configuration + (set-window-configuration owdriver--window-configuration)) + (when owdriver--marker + (select-window (get-buffer-window (marker-buffer owdriver--marker))) + (goto-char (marker-position owdriver--marker))) + (setq owdriver--window-configuration nil) + (setq owdriver--marker nil) + (owdriver-mode 0))) + +;;;###autoload +(defun owdriver-start () + "Start driving the window of `owdriver--window'." + (interactive) + (setq owdriver--marker (set-marker (make-marker) (point) (current-buffer))) + (setq owdriver--window-configuration (current-window-configuration)) + (when (not (window-live-p owdriver--window)) + (owdriver-next-window)) + (select-window owdriver--window) + (owdriver-mode 1)) + +;;;###autoload (defun owdriver-next-window (&optional reverse) "Change the window of `owdriver--window'." (interactive) @@ -255,8 +289,6 @@ (yaxception:throw e)) (yaxception:finally (delete-overlay ov))))) - ;; Return to working window at last - (select-window actwnd) (setq owdriver--window nextwnd) (owdriver--show-message "Drived window is '%s'" owdriver--window))) (yaxception:catch 'error e @@ -265,11 +297,13 @@ (yaxception:get-text e) (yaxception:get-stack-trace-string e))))) +;;;###autoload (defun owdriver-previous-window () "Change the window of `owdriver--window'." (interactive) (owdriver-next-window t)) +;;;###autoload (defun owdriver-focus-window () "Quit driving `owdriver--window' and move to `owdriver--window'." (interactive) @@ -277,6 +311,7 @@ (select-window owdriver--window) (keyboard-quit))) +;;;###autoload (defun owdriver-quit () "Quit driving `owdriver--window'." (interactive) @@ -293,19 +328,13 @@ (when (and (stringp keystroke) (not (string= keystroke "")) (commandp command)) - (define-key owdriver-mode-map - (read-kbd-macro (concat owdriver-prefix-key " " keystroke)) - command) - (owdriver--awhen (assoc keystroke owdriver--keymap-alist) - (setq owdriver--keymap-alist (delq it owdriver--keymap-alist))) - (add-to-list 'owdriver--keymap-alist `(,keystroke . ,command)))) + (define-key owdriver-mode-map (read-kbd-macro keystroke) command))) ;;;###autoload -(defmacro owdriver-define-command (command add-keymap &rest body) +(defmacro owdriver-define-command (command &rest body) "Define the command for driving `owdriver--window' from COMMAND. The command named `owdriver-do-COMMAND' is defined by this function. -ADD-KEYMAP is boolean. If non-nil, do `owdriver-add-keymap' using the key bound to COMMAND in `global-map'. BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is no need." (declare (indent 2)) (let* ((body (or body `((call-interactively ',command)))) @@ -314,7 +343,7 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (fcommand (intern (concat "owdriver-do-" cmdnm "-on-next-window"))) (tasknm (replace-regexp-in-string "-" " " cmdnm))) `(progn - (owdriver--trace "start define command[%s]. add-keymap[%s]" ,cmdnm ,add-keymap) + (owdriver--trace "start define command[%s]" ,cmdnm) ;;;###autoload (defun ,ncommand (&optional arg) ,(format "Do `%s' in `owdriver--window'.\n\nIf prefix argument is given, do `owdriver-next-window' before that." cmdnm) @@ -322,14 +351,12 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (let ((force-next-window (and arg (> arg 1)))) (owdriver--with-selected-window ,tasknm force-next-window ,@body))) + ;;;###autoload (defun ,fcommand () ,(format "Do `%s' in `owdriver--window' with `owdriver-next-window'." cmdnm) (interactive) (owdriver--with-selected-window ,tasknm t - ,@body)) - (when ,add-keymap - (dolist (k (owdriver--get-binding-keys ',command)) - (owdriver-add-keymap k ',ncommand)))))) + ,@body))))) ;;;###autoload (defun owdriver-config-default () @@ -339,26 +366,16 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (owdriver-add-keymap "C-S-o" 'owdriver-previous-window) (owdriver-add-keymap "" 'owdriver-focus-window) ;; Basic command - (owdriver-define-command scroll-up t) - (owdriver-define-command scroll-up-command t) - (owdriver-define-command scroll-down t) - (owdriver-define-command scroll-down-command t) - (owdriver-define-command scroll-left t (scroll-left 10 t)) - (owdriver-define-command scroll-right t (scroll-right 10 t)) - (owdriver-define-command next-line t) - (owdriver-define-command previous-line t) - (owdriver-define-command forward-char t) - (owdriver-define-command forward-word t) - (owdriver-define-command backward-char t) - (owdriver-define-command backward-word t) - (owdriver-define-command move-beginning-of-line t) - (owdriver-define-command move-end-of-line t) - (owdriver-define-command beginning-of-buffer t) - (owdriver-define-command end-of-buffer t) - (owdriver-define-command isearch-forward t (isearch-forward)) - (owdriver-define-command isearch-backward t (isearch-backward)) - (owdriver-define-command set-mark-command t) - (owdriver-define-command kill-ring-save t (call-interactively 'kill-ring-save) (deactivate-mark)) + (owdriver-define-command scroll-up) + (owdriver-define-command scroll-up-command) + (owdriver-define-command scroll-down) + (owdriver-define-command scroll-down-command) + (owdriver-define-command scroll-left (scroll-left 10 t)) + (owdriver-define-command scroll-right (scroll-right 10 t)) + (owdriver-define-command move-beginning-of-line) + (owdriver-define-command move-end-of-line) + (owdriver-define-command beginning-of-buffer) + (owdriver-define-command end-of-buffer) ;; Patch for Emacs 26.1 (when (>= emacs-major-version 26) From bbbe78862cb934541333483216a3baca050e8eca Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Mon, 24 Oct 2022 01:23:53 +0900 Subject: [PATCH 06/24] Fix owdriver-keep-driving-command-regexp to be customizable --- owdriver.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index 57b8bbd..08e3e3e 100644 --- a/owdriver.el +++ b/owdriver.el @@ -209,10 +209,13 @@ (defvar owdriver--marker nil) (defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) (defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) -(defvar owdriver-keep-driving-command-regexp (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes))))) +(defvar owdriver-keep-driving-command-regexp nil) (defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) (defun owdriver--keep-driving-with-default (command) + (when (not owdriver-keep-driving-command-regexp) + (setq owdriver-keep-driving-command-regexp + (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) (or (memq command owdriver-keep-driving-commands) (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) From 7aa0ba302ebdfbb25206793fbfaff877b870a3fc Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Tue, 25 Oct 2022 21:04:34 +0900 Subject: [PATCH 07/24] Fix owdriver--with-selected-window --- owdriver.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/owdriver.el b/owdriver.el index 08e3e3e..4a0eb78 100644 --- a/owdriver.el +++ b/owdriver.el @@ -147,11 +147,11 @@ (yaxception:try (owdriver--trace "start with select window : wnd[%s] force-next-window[%s]" owdriver--window ,force-next-window) - (when (or ,force-next-window - (not (window-live-p owdriver--window)) - (eq owdriver--window (nth 0 (get-buffer-window-list)))) - (let ((owdriver--move-window-amount 1)) - (owdriver-next-window))) + (when (or ,force-next-window (not (window-live-p owdriver--window))) + (let ((owdriver--move-window-amount 1) + (w (get-buffer-window))) + (owdriver-next-window) + (select-window w))) (with-selected-window owdriver--window ,@body)) (yaxception:catch 'error e From c25054ff3f255b3eba2cdc9b1728eec6c14124f0 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Tue, 25 Oct 2022 21:41:30 +0900 Subject: [PATCH 08/24] Change keymap --- owdriver.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index 4a0eb78..b6b9493 100644 --- a/owdriver.el +++ b/owdriver.el @@ -367,7 +367,8 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n ;; Own command (owdriver-add-keymap "C-o" 'owdriver-next-window) (owdriver-add-keymap "C-S-o" 'owdriver-previous-window) - (owdriver-add-keymap "" 'owdriver-focus-window) + (owdriver-add-keymap "C-c C-k" 'owdriver-focus-window) + (owdriver-add-keymap "C-c C-c" 'owdriver-quit) ;; Basic command (owdriver-define-command scroll-up) (owdriver-define-command scroll-up-command) From 752bd9caf7e41a3069c1b92cfb2bcae5f4a1afdf Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Tue, 25 Oct 2022 21:44:38 +0900 Subject: [PATCH 09/24] Fix debug code --- owdriver.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index b6b9493..79969e3 100644 --- a/owdriver.el +++ b/owdriver.el @@ -222,7 +222,7 @@ (defun owdriver--cleanup () (when (and owdriver-mode (not (funcall owdriver-keep-driving-function this-command))) - (message "OWSTOP! %s" this-command) + (owdriver--trace "start cleanup. this-command[%s]" this-command) (when owdriver--window-configuration (set-window-configuration owdriver--window-configuration)) (when owdriver--marker From a602a9e24854a06c9f7023344f28d9a48f4c0bce Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Tue, 25 Oct 2022 21:44:53 +0900 Subject: [PATCH 10/24] Cosme --- owdriver.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/owdriver.el b/owdriver.el index 79969e3..57b9be7 100644 --- a/owdriver.el +++ b/owdriver.el @@ -365,8 +365,8 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (defun owdriver-config-default () "Do the recommended configuration." ;; Own command - (owdriver-add-keymap "C-o" 'owdriver-next-window) - (owdriver-add-keymap "C-S-o" 'owdriver-previous-window) + (owdriver-add-keymap "C-o" 'owdriver-next-window) + (owdriver-add-keymap "C-S-o" 'owdriver-previous-window) (owdriver-add-keymap "C-c C-k" 'owdriver-focus-window) (owdriver-add-keymap "C-c C-c" 'owdriver-quit) ;; Basic command From 52ae0b196f0e829c7a69f51b6974e07cbd1f7aad Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Tue, 25 Oct 2022 21:47:22 +0900 Subject: [PATCH 11/24] Cosme --- owdriver.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index 57b9be7..9515714 100644 --- a/owdriver.el +++ b/owdriver.el @@ -240,7 +240,8 @@ (setq owdriver--window-configuration (current-window-configuration)) (when (not (window-live-p owdriver--window)) (owdriver-next-window)) - (select-window owdriver--window) + (when (not (eq (get-buffer-window) owdriver--window)) + (select-window owdriver--window)) (owdriver-mode 1)) ;;;###autoload From 1974330d7ef0a13f5ee55767b65bb7f0e545e085 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Wed, 26 Oct 2022 18:36:47 +0900 Subject: [PATCH 12/24] Fix not to use with-selected-window that seems to cause a freeze if window-configuration changed happens --- owdriver.el | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/owdriver.el b/owdriver.el index 9515714..79805ab 100644 --- a/owdriver.el +++ b/owdriver.el @@ -141,23 +141,20 @@ (declare (indent 1)) `(let ((it ,test)) (when it ,@body))) -(defmacro owdriver--with-selected-window (tasknm force-next-window &rest body) +(defmacro owdriver--with-selected-window (command force-next-window &rest body) (declare (indent 2)) `(yaxception:$ (yaxception:try (owdriver--trace "start with select window : wnd[%s] force-next-window[%s]" owdriver--window ,force-next-window) - (when (or ,force-next-window (not (window-live-p owdriver--window))) - (let ((owdriver--move-window-amount 1) - (w (get-buffer-window))) - (owdriver-next-window) - (select-window w))) - (with-selected-window owdriver--window + (let ((owdriver--move-window-amount 1) + (owdriver-keep-driving-function (lambda (c) (eq c ',command)))) + (owdriver-start ,force-next-window) ,@body)) (yaxception:catch 'error e - (owdriver--show-message "Failed %s : %s" ,tasknm (yaxception:get-text e)) + (owdriver--show-message "Failed %s : %s" ',command (yaxception:get-text e)) (owdriver--error "failed %s : %s\n%s" - ,tasknm + ',command (yaxception:get-text e) (yaxception:get-stack-trace-string e))))) @@ -223,9 +220,10 @@ (when (and owdriver-mode (not (funcall owdriver-keep-driving-function this-command))) (owdriver--trace "start cleanup. this-command[%s]" this-command) - (when owdriver--window-configuration - (set-window-configuration owdriver--window-configuration)) (when owdriver--marker + (when (and (not (window-live-p (get-buffer-window (marker-buffer owdriver--marker)))) + owdriver--window-configuration) + (set-window-configuration owdriver--window-configuration)) (select-window (get-buffer-window (marker-buffer owdriver--marker))) (goto-char (marker-position owdriver--marker))) (setq owdriver--window-configuration nil) @@ -233,12 +231,13 @@ (owdriver-mode 0))) ;;;###autoload -(defun owdriver-start () +(defun owdriver-start (&optional force-next-window) "Start driving the window of `owdriver--window'." (interactive) (setq owdriver--marker (set-marker (make-marker) (point) (current-buffer))) (setq owdriver--window-configuration (current-window-configuration)) - (when (not (window-live-p owdriver--window)) + (when (or force-next-window + (not (window-live-p owdriver--window))) (owdriver-next-window)) (when (not (eq (get-buffer-window) owdriver--window)) (select-window owdriver--window)) @@ -344,8 +343,7 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (let* ((body (or body `((call-interactively ',command)))) (cmdnm (symbol-name command)) (ncommand (intern (concat "owdriver-do-" cmdnm))) - (fcommand (intern (concat "owdriver-do-" cmdnm "-on-next-window"))) - (tasknm (replace-regexp-in-string "-" " " cmdnm))) + (fcommand (intern (concat "owdriver-do-" cmdnm "-on-next-window")))) `(progn (owdriver--trace "start define command[%s]" ,cmdnm) ;;;###autoload @@ -353,13 +351,13 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n ,(format "Do `%s' in `owdriver--window'.\n\nIf prefix argument is given, do `owdriver-next-window' before that." cmdnm) (interactive "p") (let ((force-next-window (and arg (> arg 1)))) - (owdriver--with-selected-window ,tasknm force-next-window + (owdriver--with-selected-window ,ncommand force-next-window ,@body))) ;;;###autoload (defun ,fcommand () ,(format "Do `%s' in `owdriver--window' with `owdriver-next-window'." cmdnm) (interactive) - (owdriver--with-selected-window ,tasknm t + (owdriver--with-selected-window ,fcommand t ,@body))))) ;;;###autoload From 5517fc9aaaba0faae91dc6d5ec4d891a9f1e8337 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 18:30:36 +0900 Subject: [PATCH 13/24] Fix owdriver-keep-driving-function for owdriver--with-selected-window --- owdriver.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index 79805ab..4ad88b6 100644 --- a/owdriver.el +++ b/owdriver.el @@ -148,7 +148,7 @@ (owdriver--trace "start with select window : wnd[%s] force-next-window[%s]" owdriver--window ,force-next-window) (let ((owdriver--move-window-amount 1) - (owdriver-keep-driving-function (lambda (c) (eq c ',command)))) + (owdriver-keep-driving-function (lambda (c) nil))) (owdriver-start ,force-next-window) ,@body)) (yaxception:catch 'error e From 8f4a8bbe1f3337668e69ca72bf0d5c56a75a9835 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 18:32:44 +0900 Subject: [PATCH 14/24] Cosme --- owdriver.el | 119 +++++++++++++--------------------------------------- 1 file changed, 30 insertions(+), 89 deletions(-) diff --git a/owdriver.el b/owdriver.el index 4ad88b6..fe69007 100644 --- a/owdriver.el +++ b/owdriver.el @@ -27,75 +27,9 @@ ;; other windows quickly in multi window situation. ;; In default, that's move, scroll and isearch. ;; Moreover, you can add the action what you want. - -;;; Dependency: -;; -;; - yaxception.el ( see ) -;; - log4e.el ( see ) - -;;; Installation: -;; -;; Put this to your load-path. -;; And put the following lines in your .emacs or site-start.el file. -;; -;; (require 'owdriver) - -;;; Configuration: -;; -;; ;; Make config suit for you. About the config item, see Customization or eval the following sexp. -;; ;; (customize-group "owdriver") -;; -;; ;; If you want to do the default config -;; (owdriver-config-default) -;; -;; (owdriver-mode 1) - -;;; Customization: -;; -;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "owdriver-[^-]" :docstring t) -;; `owdriver-prefix-key' -;; String of the prefix keystroke for `owdriver-mode-map'. -;; `owdriver-next-window-prefer-pophint' -;; Whether to prefer to use `pophint:do' for `owdriver-next-window'. -;; -;; *** END auto-documentation - -;;; API: -;; -;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "owdriver-[^-]" :docstring t) -;; `owdriver-next-window' -;; Change the window of `owdriver--window'. -;; `owdriver-previous-window' -;; Change the window of `owdriver--window'. -;; `owdriver-focus-window' -;; Quit driving `owdriver--window' and move to `owdriver--window'. -;; `owdriver-quit' -;; Quit driving `owdriver--window'. -;; -;; *** END auto-documentation -;; [EVAL] (autodoc-document-lisp-buffer :type 'macro :prefix "owdriver-[^-]" :docstring t) -;; `owdriver-define-command' -;; Define the command for driving `owdriver--window' from COMMAND. -;; -;; *** END auto-documentation -;; [EVAL] (autodoc-document-lisp-buffer :type 'function :prefix "owdriver-[^-]" :docstring t) -;; `owdriver-add-keymap' -;; Add the keymap of `owdriver-mode-map'. -;; `owdriver-config-default' -;; Do the recommended configuration. -;; -;; *** END auto-documentation -;; [Note] Functions and variables other than listed above, Those specifications may be changed without notice. - -;;; Tested On: -;; -;; - Emacs ... GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 Version 10.10.5 (Build 14F2511)) of 2018-05-31 -;; - yaxception.el ... Version 0.2.0 -;; - log4e.el ... Version 0.2.0 - - ;; Enjoy!!! +;;; Code: (eval-when-compile (require 'cl-lib)) (require 'log4e) @@ -183,9 +117,18 @@ ;;;;;;;;;; ;; Mode +(defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) +(defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) +(defvar owdriver-keep-driving-command-regexp nil) +(defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) + ;;;###autoload (defvar owdriver-mode-map (make-sparse-keymap)) +(defvar owdriver--window-configuration nil) +(defvar owdriver--marker nil) +(defvar owdriver--keep-driving-function nil) + ;;;###autoload (define-minor-mode owdriver-mode "Quickly perform various actions on other windows." @@ -195,20 +138,26 @@ :global t :group 'owdriver (if owdriver-mode - (add-hook 'pre-command-hook 'owdriver--cleanup) + (progn + (setq owdriver--marker (set-marker (make-marker) (point) (current-buffer))) + (setq owdriver--window-configuration (current-window-configuration)) + (setq owdriver--keep-driving-function owdriver-keep-driving-function) + (add-hook 'pre-command-hook 'owdriver--cleanup)) + (when owdriver--marker + (when (and (not (window-live-p (get-buffer-window (marker-buffer owdriver--marker)))) + owdriver--window-configuration) + (set-window-configuration owdriver--window-configuration)) + (select-window (get-buffer-window (marker-buffer owdriver--marker))) + (goto-char (marker-position owdriver--marker))) + (setq owdriver--marker nil) + (setq owdriver--window-configuration nil) + (setq owdriver--keep-driving-function nil) (remove-hook 'pre-command-hook 'owdriver--cleanup))) ;;;;;;;;;;;;;;;;;; ;; User Command -(defvar owdriver--window-configuration nil) -(defvar owdriver--marker nil) -(defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) -(defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) -(defvar owdriver-keep-driving-command-regexp nil) -(defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) - (defun owdriver--keep-driving-with-default (command) (when (not owdriver-keep-driving-command-regexp) (setq owdriver-keep-driving-command-regexp @@ -218,30 +167,22 @@ (defun owdriver--cleanup () (when (and owdriver-mode - (not (funcall owdriver-keep-driving-function this-command))) - (owdriver--trace "start cleanup. this-command[%s]" this-command) - (when owdriver--marker - (when (and (not (window-live-p (get-buffer-window (marker-buffer owdriver--marker)))) - owdriver--window-configuration) - (set-window-configuration owdriver--window-configuration)) - (select-window (get-buffer-window (marker-buffer owdriver--marker))) - (goto-char (marker-position owdriver--marker))) - (setq owdriver--window-configuration nil) - (setq owdriver--marker nil) + (not (active-minibuffer-window)) + (functionp owdriver--keep-driving-function) + (not (funcall owdriver--keep-driving-function this-command))) + (message "start cleanup. this-command[%s]" this-command) (owdriver-mode 0))) ;;;###autoload (defun owdriver-start (&optional force-next-window) "Start driving the window of `owdriver--window'." (interactive) - (setq owdriver--marker (set-marker (make-marker) (point) (current-buffer))) - (setq owdriver--window-configuration (current-window-configuration)) + (owdriver-mode 1) (when (or force-next-window (not (window-live-p owdriver--window))) (owdriver-next-window)) (when (not (eq (get-buffer-window) owdriver--window)) - (select-window owdriver--window)) - (owdriver-mode 1)) + (select-window owdriver--window))) ;;;###autoload (defun owdriver-next-window (&optional reverse) From 4e0b3e59bc1fd04e92016418650b0ad1c705dfb1 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 19:20:57 +0900 Subject: [PATCH 15/24] Fix bug in how to restore start situation --- owdriver.el | 63 ++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/owdriver.el b/owdriver.el index fe69007..7e02cde 100644 --- a/owdriver.el +++ b/owdriver.el @@ -50,6 +50,11 @@ :type 'boolean :group 'owdriver) +(defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) +(defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) +(defvar owdriver-keep-driving-command-regexp nil) +(defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) + (log4e:deflogger "owdriver" "%t [%l] %m" "%H:%M:%S" '((fatal . "fatal") (error . "error") @@ -62,6 +67,8 @@ (defvar owdriver--window nil "Current window drived by the command of `owdriver-mode-map'.") (defvar owdriver--move-window-amount nil) +(defvar owdriver--start-location nil) +(defvar owdriver--keep-driving-function nil) ;;;;;;;;;;;;; @@ -113,22 +120,28 @@ finally return (progn (owdriver--trace "got keybind : %s" ret) ret))) +(defun owdriver--keep-driving-with-default (command) + (when (not owdriver-keep-driving-command-regexp) + (setq owdriver-keep-driving-command-regexp + (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) + (or (memq command owdriver-keep-driving-commands) + (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) + +(defun owdriver--cleanup () + (when (and owdriver-mode + (not (active-minibuffer-window)) + (functionp owdriver--keep-driving-function) + (not (funcall owdriver--keep-driving-function this-command))) + (owdriver--trace "start cleanup. this-command[%s]" this-command) + (owdriver-mode 0))) + ;;;;;;;;;; ;; Mode -(defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) -(defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) -(defvar owdriver-keep-driving-command-regexp nil) -(defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) - ;;;###autoload (defvar owdriver-mode-map (make-sparse-keymap)) -(defvar owdriver--window-configuration nil) -(defvar owdriver--marker nil) -(defvar owdriver--keep-driving-function nil) - ;;;###autoload (define-minor-mode owdriver-mode "Quickly perform various actions on other windows." @@ -139,18 +152,15 @@ :group 'owdriver (if owdriver-mode (progn - (setq owdriver--marker (set-marker (make-marker) (point) (current-buffer))) - (setq owdriver--window-configuration (current-window-configuration)) + (setq owdriver--start-location `(:window ,(selected-window) :point ,(window-point), :config ,(current-window-configuration))) (setq owdriver--keep-driving-function owdriver-keep-driving-function) (add-hook 'pre-command-hook 'owdriver--cleanup)) - (when owdriver--marker - (when (and (not (window-live-p (get-buffer-window (marker-buffer owdriver--marker)))) - owdriver--window-configuration) - (set-window-configuration owdriver--window-configuration)) - (select-window (get-buffer-window (marker-buffer owdriver--marker))) - (goto-char (marker-position owdriver--marker))) - (setq owdriver--marker nil) - (setq owdriver--window-configuration nil) + (when owdriver--start-location + (when (not (window-live-p (plist-get owdriver--start-location :window))) + (set-window-configuration (plist-get owdriver--start-location :config))) + (select-window (plist-get owdriver--start-location :window)) + (set-window-point (plist-get owdriver--start-location :window) (plist-get owdriver--start-location :point)) + (setq owdriver--start-location nil)) (setq owdriver--keep-driving-function nil) (remove-hook 'pre-command-hook 'owdriver--cleanup))) @@ -158,21 +168,6 @@ ;;;;;;;;;;;;;;;;;; ;; User Command -(defun owdriver--keep-driving-with-default (command) - (when (not owdriver-keep-driving-command-regexp) - (setq owdriver-keep-driving-command-regexp - (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) - (or (memq command owdriver-keep-driving-commands) - (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) - -(defun owdriver--cleanup () - (when (and owdriver-mode - (not (active-minibuffer-window)) - (functionp owdriver--keep-driving-function) - (not (funcall owdriver--keep-driving-function this-command))) - (message "start cleanup. this-command[%s]" this-command) - (owdriver-mode 0))) - ;;;###autoload (defun owdriver-start (&optional force-next-window) "Start driving the window of `owdriver--window'." From 83a35cd77cd566998e089292071440802b4da2ca Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 19:24:19 +0900 Subject: [PATCH 16/24] Fix owdriver-config-default --- owdriver.el | 2 -- 1 file changed, 2 deletions(-) diff --git a/owdriver.el b/owdriver.el index 7e02cde..3a33435 100644 --- a/owdriver.el +++ b/owdriver.el @@ -311,8 +311,6 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n (owdriver-define-command scroll-down-command) (owdriver-define-command scroll-left (scroll-left 10 t)) (owdriver-define-command scroll-right (scroll-right 10 t)) - (owdriver-define-command move-beginning-of-line) - (owdriver-define-command move-end-of-line) (owdriver-define-command beginning-of-buffer) (owdriver-define-command end-of-buffer) From b8ed75d1bd37baf8cad7ffb1d378168926d90928 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 19:38:21 +0900 Subject: [PATCH 17/24] Cosme --- owdriver.el | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/owdriver.el b/owdriver.el index 3a33435..54b8cfa 100644 --- a/owdriver.el +++ b/owdriver.el @@ -50,10 +50,26 @@ :type 'boolean :group 'owdriver) -(defvar owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window)) -(defvar owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-")) -(defvar owdriver-keep-driving-command-regexp nil) -(defvar owdriver-keep-driving-function 'owdriver--keep-driving-with-default) +(defcustom owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window) + "List of command kept handling by `owdriver--keep-driving-with-default'." + :type (list 'function) + :group 'owdriver) + +(defcustom owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-") + "List of command prefix kept handling by `owdriver--keep-driving-with-default'. +This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil." + :type (list 'string) + :group 'owdriver) + +(defcustom owdriver-keep-driving-command-regexp nil + "Regexp for matching commands kept handling by `owdriver--keep-driving-with-default'." + :type 'regexp + :group 'owdriver) + +(defcustom owdriver-keep-driving-function 'owdriver--keep-driving-with-default + "Function to judge to keep handling by owdriver." + :type 'function + :group 'owdriver) (log4e:deflogger "owdriver" "%t [%l] %m" "%H:%M:%S" '((fatal . "fatal") From d3eb2c9ecec9930f1f43f55362d7b125102a1255 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 19:48:24 +0900 Subject: [PATCH 18/24] Add defcustom owdriver-next-window-function --- owdriver.el | 120 ++++++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 56 deletions(-) diff --git a/owdriver.el b/owdriver.el index 54b8cfa..0dbbd89 100644 --- a/owdriver.el +++ b/owdriver.el @@ -46,10 +46,15 @@ :group 'owdriver) (defcustom owdriver-next-window-prefer-pophint t - "Whether to prefer to use `pophint:do' for `owdriver-next-window'." + "Whether to prefer to use `pophint:do' for `owdriver--default-next-window'." :type 'boolean :group 'owdriver) +(defcustom owdriver-next-window-function 'owdriver--default-next-window + "Function to find a next window handled by owdriver." + :type 'function + :group 'owdriver) + (defcustom owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window) "List of command kept handling by `owdriver--keep-driving-with-default'." :type (list 'function) @@ -136,13 +141,6 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil finally return (progn (owdriver--trace "got keybind : %s" ret) ret))) -(defun owdriver--keep-driving-with-default (command) - (when (not owdriver-keep-driving-command-regexp) - (setq owdriver-keep-driving-command-regexp - (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) - (or (memq command owdriver-keep-driving-commands) - (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) - (defun owdriver--cleanup () (when (and owdriver-mode (not (active-minibuffer-window)) @@ -151,54 +149,14 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (owdriver--trace "start cleanup. this-command[%s]" this-command) (owdriver-mode 0))) +(defun owdriver--keep-driving-with-default (command) + (when (not owdriver-keep-driving-command-regexp) + (setq owdriver-keep-driving-command-regexp + (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) + (or (memq command owdriver-keep-driving-commands) + (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) -;;;;;;;;;; -;; Mode - -;;;###autoload -(defvar owdriver-mode-map (make-sparse-keymap)) - -;;;###autoload -(define-minor-mode owdriver-mode - "Quickly perform various actions on other windows." - :init-value nil - :lighter " OW" - :keymap owdriver-mode-map - :global t - :group 'owdriver - (if owdriver-mode - (progn - (setq owdriver--start-location `(:window ,(selected-window) :point ,(window-point), :config ,(current-window-configuration))) - (setq owdriver--keep-driving-function owdriver-keep-driving-function) - (add-hook 'pre-command-hook 'owdriver--cleanup)) - (when owdriver--start-location - (when (not (window-live-p (plist-get owdriver--start-location :window))) - (set-window-configuration (plist-get owdriver--start-location :config))) - (select-window (plist-get owdriver--start-location :window)) - (set-window-point (plist-get owdriver--start-location :window) (plist-get owdriver--start-location :point)) - (setq owdriver--start-location nil)) - (setq owdriver--keep-driving-function nil) - (remove-hook 'pre-command-hook 'owdriver--cleanup))) - - -;;;;;;;;;;;;;;;;;; -;; User Command - -;;;###autoload -(defun owdriver-start (&optional force-next-window) - "Start driving the window of `owdriver--window'." - (interactive) - (owdriver-mode 1) - (when (or force-next-window - (not (window-live-p owdriver--window))) - (owdriver-next-window)) - (when (not (eq (get-buffer-window) owdriver--window)) - (select-window owdriver--window))) - -;;;###autoload -(defun owdriver-next-window (&optional reverse) - "Change the window of `owdriver--window'." - (interactive) +(defun owdriver--default-next-window (&optional reverse) (yaxception:$ (yaxception:try (let* ((actwnd (get-buffer-window)) @@ -252,11 +210,61 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (yaxception:get-text e) (yaxception:get-stack-trace-string e))))) + +;;;;;;;;;; +;; Mode + +;;;###autoload +(defvar owdriver-mode-map (make-sparse-keymap)) + +;;;###autoload +(define-minor-mode owdriver-mode + "Quickly perform various actions on other windows." + :init-value nil + :lighter " OW" + :keymap owdriver-mode-map + :global t + :group 'owdriver + (if owdriver-mode + (progn + (setq owdriver--start-location `(:window ,(selected-window) :point ,(window-point), :config ,(current-window-configuration))) + (setq owdriver--keep-driving-function owdriver-keep-driving-function) + (add-hook 'pre-command-hook 'owdriver--cleanup)) + (when owdriver--start-location + (when (not (window-live-p (plist-get owdriver--start-location :window))) + (set-window-configuration (plist-get owdriver--start-location :config))) + (select-window (plist-get owdriver--start-location :window)) + (set-window-point (plist-get owdriver--start-location :window) (plist-get owdriver--start-location :point)) + (setq owdriver--start-location nil)) + (setq owdriver--keep-driving-function nil) + (remove-hook 'pre-command-hook 'owdriver--cleanup))) + + +;;;;;;;;;;;;;;;;;; +;; User Command + +;;;###autoload +(defun owdriver-start (&optional force-next-window) + "Start driving the window of `owdriver--window'." + (interactive) + (owdriver-mode 1) + (when (or force-next-window + (not (window-live-p owdriver--window))) + (owdriver-next-window)) + (when (not (eq (get-buffer-window) owdriver--window)) + (select-window owdriver--window))) + +;;;###autoload +(defun owdriver-next-window () + "Change the window of `owdriver--window'." + (interactive) + (funcall owdriver-next-window-function)) + ;;;###autoload (defun owdriver-previous-window () "Change the window of `owdriver--window'." (interactive) - (owdriver-next-window t)) + (funcall owdriver-next-window-function t)) ;;;###autoload (defun owdriver-focus-window () From b46ba327f503e894ba55cd6122e2cbe99b6f697d Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 30 Oct 2022 20:10:31 +0900 Subject: [PATCH 19/24] Cosme --- owdriver.el | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/owdriver.el b/owdriver.el index 0dbbd89..debc5b3 100644 --- a/owdriver.el +++ b/owdriver.el @@ -46,32 +46,32 @@ :group 'owdriver) (defcustom owdriver-next-window-prefer-pophint t - "Whether to prefer to use `pophint:do' for `owdriver--default-next-window'." + "Whether to prefer to use `pophint:do' for `owdriver-find-next-window'." :type 'boolean :group 'owdriver) -(defcustom owdriver-next-window-function 'owdriver--default-next-window +(defcustom owdriver-next-window-function 'owdriver-find-next-window "Function to find a next window handled by owdriver." :type 'function :group 'owdriver) (defcustom owdriver-keep-driving-commands '(owdriver-start owdriver-next-window owdriver-previous-window) - "List of command kept handling by `owdriver--keep-driving-with-default'." + "List of command kept handling by `owdriver-keep-driving-p'." :type (list 'function) :group 'owdriver) (defcustom owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-") - "List of command prefix kept handling by `owdriver--keep-driving-with-default'. + "List of command prefix kept handling by `owdriver-keep-driving-p'. This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil." :type (list 'string) :group 'owdriver) (defcustom owdriver-keep-driving-command-regexp nil - "Regexp for matching commands kept handling by `owdriver--keep-driving-with-default'." + "Regexp for matching commands kept handling by `owdriver-keep-driving-p'." :type 'regexp :group 'owdriver) -(defcustom owdriver-keep-driving-function 'owdriver--keep-driving-with-default +(defcustom owdriver-keep-driving-function 'owdriver-keep-driving-p "Function to judge to keep handling by owdriver." :type 'function :group 'owdriver) @@ -149,14 +149,11 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (owdriver--trace "start cleanup. this-command[%s]" this-command) (owdriver-mode 0))) -(defun owdriver--keep-driving-with-default (command) - (when (not owdriver-keep-driving-command-regexp) - (setq owdriver-keep-driving-command-regexp - (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) - (or (memq command owdriver-keep-driving-commands) - (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) -(defun owdriver--default-next-window (&optional reverse) +;;;;;;;;;;;;;; +;; Function + +(defun owdriver-find-next-window (&optional reverse) (yaxception:$ (yaxception:try (let* ((actwnd (get-buffer-window)) @@ -210,6 +207,13 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (yaxception:get-text e) (yaxception:get-stack-trace-string e))))) +(defun owdriver-keep-driving-p (command) + (when (not owdriver-keep-driving-command-regexp) + (setq owdriver-keep-driving-command-regexp + (rx-to-string `(and bos (regexp ,(regexp-opt owdriver-keep-driving-command-prefixes)))))) + (or (memq command owdriver-keep-driving-commands) + (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) + ;;;;;;;;;; ;; Mode @@ -258,7 +262,7 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (defun owdriver-next-window () "Change the window of `owdriver--window'." (interactive) - (funcall owdriver-next-window-function)) + (funcall owdriver-next-window-function nil)) ;;;###autoload (defun owdriver-previous-window () From 001fe513c1a9dd807c21218f24257b3702340d95 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Mon, 31 Oct 2022 01:41:22 +0900 Subject: [PATCH 20/24] Fix bug in owdriver-next-window --- owdriver.el | 95 ++++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 60 deletions(-) diff --git a/owdriver.el b/owdriver.el index debc5b3..15ddafa 100644 --- a/owdriver.el +++ b/owdriver.el @@ -87,7 +87,6 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (defvar owdriver--window nil "Current window drived by the command of `owdriver-mode-map'.") -(defvar owdriver--move-window-amount nil) (defvar owdriver--start-location nil) (defvar owdriver--keep-driving-function nil) @@ -109,8 +108,7 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (yaxception:try (owdriver--trace "start with select window : wnd[%s] force-next-window[%s]" owdriver--window ,force-next-window) - (let ((owdriver--move-window-amount 1) - (owdriver-keep-driving-function (lambda (c) nil))) + (let ((owdriver-keep-driving-function (lambda (c) nil))) (owdriver-start ,force-next-window) ,@body)) (yaxception:catch 'error e @@ -153,59 +151,24 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil ;;;;;;;;;;;;;; ;; Function -(defun owdriver-find-next-window (&optional reverse) - (yaxception:$ - (yaxception:try - (let* ((actwnd (get-buffer-window)) - (currwnd (if (window-live-p owdriver--window) owdriver--window actwnd)) - (move-amount (or owdriver--move-window-amount - (when (window-live-p owdriver--window) 1) - 2)) - (is-nextable-window (lambda (w) - (and (window-live-p w) - (not (eq w actwnd)) - (not (eq w currwnd)) - (not (minibufferp (window-buffer w)))))) - nextwnd popwnd wndloc) - (select-window currwnd) - (owdriver--trace "start %s window. currwnd[%s] move-amount[%s]" - (if reverse "previous" "next") (selected-window) move-amount) - ;; Move to next target window - (if (and (and owdriver-next-window-prefer-pophint - (featurep 'pophint) - (boundp 'pophint--next-window-source) - (>= (cl-loop for w in (window-list) count (funcall is-nextable-window w)) 2))) - (setq nextwnd (when-let ((hint (pophint:do :source pophint--next-window-source :allwindow t))) - (pophint:hint-window hint))) - (while (and (> move-amount 0) - (not (eq nextwnd currwnd))) - (other-window (if reverse -1 1)) - (setq nextwnd (get-buffer-window)) - (owdriver--trace "selected next window : %s" nextwnd) - (when (funcall is-nextable-window nextwnd) - (cl-decf move-amount) - (owdriver--trace "decremented move-amount[%s]" move-amount)))) - ;; Blink target window after move - (when (not (eq nextwnd currwnd)) - (owdriver--trace "start blink window : %s" nextwnd) - (let ((ov (make-overlay (window-start) (window-end)))) - (yaxception:$ - (yaxception:try - (overlay-put ov 'face 'highlight) - (select-window actwnd) - (sit-for 0.1) - (select-window nextwnd)) - (yaxception:catch 'error e - (yaxception:throw e)) - (yaxception:finally - (delete-overlay ov))))) - (setq owdriver--window nextwnd) - (owdriver--show-message "Drived window is '%s'" owdriver--window))) - (yaxception:catch 'error e - (owdriver--show-message "Failed next window : %s" (yaxception:get-text e)) - (owdriver--error "failed next window : %s\n%s" - (yaxception:get-text e) - (yaxception:get-stack-trace-string e))))) +(defun owdriver-find-next-window (reverse) + (let* ((actwnd (get-buffer-window)) + (currwnd (if (window-live-p owdriver--window) owdriver--window actwnd)) + (is-nextable-window (lambda (w) + (and (window-live-p w) + (not (eq w actwnd)) + (not (eq w currwnd)) + (not (minibufferp (window-buffer w))))))) + (or (and owdriver-next-window-prefer-pophint + (featurep 'pophint) + (boundp 'pophint--next-window-source) + (>= (cl-loop for w in (window-list) count (funcall is-nextable-window w)) 2) + (when-let ((hint (pophint:do :source pophint--next-window-source :allwindow t))) + (pophint:hint-window hint))) + (progn + (select-window currwnd) + (other-window (if reverse -1 1)) + (selected-window))))) (defun owdriver-keep-driving-p (command) (when (not owdriver-keep-driving-command-regexp) @@ -255,20 +218,32 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (when (or force-next-window (not (window-live-p owdriver--window))) (owdriver-next-window)) - (when (not (eq (get-buffer-window) owdriver--window)) + (when (not (eq (selected-window) owdriver--window)) (select-window owdriver--window))) ;;;###autoload -(defun owdriver-next-window () +(defun owdriver-next-window (&optional reverse) "Change the window of `owdriver--window'." (interactive) - (funcall owdriver-next-window-function nil)) + (yaxception:$ + (yaxception:try + (setq owdriver--window (funcall owdriver-next-window-function reverse)) + (select-window owdriver--window) + (lexical-let ((ov (make-overlay (point-min) (point-max)))) + (overlay-put ov 'face 'highlight) + (run-with-idle-timer 0.1 nil (lambda () (when ov (delete-overlay ov)))) + (owdriver--show-message "Drived window is '%s'" owdriver--window))) + (yaxception:catch 'error e + (owdriver--show-message "Failed next window : %s" (yaxception:get-text e)) + (owdriver--error "failed next window : %s\n%s" + (yaxception:get-text e) + (yaxception:get-stack-trace-string e))))) ;;;###autoload (defun owdriver-previous-window () "Change the window of `owdriver--window'." (interactive) - (funcall owdriver-next-window-function t)) + (owdriver-next-window t)) ;;;###autoload (defun owdriver-focus-window () From f2bcbd429b9987f5a1981e7ae24b6d1269ac7f6d Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 4 Jun 2023 19:59:11 +0900 Subject: [PATCH 21/24] Fix owdriver--cleanup not to check active-minibuffer-window --- owdriver.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/owdriver.el b/owdriver.el index 15ddafa..4555c14 100644 --- a/owdriver.el +++ b/owdriver.el @@ -108,7 +108,7 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (yaxception:try (owdriver--trace "start with select window : wnd[%s] force-next-window[%s]" owdriver--window ,force-next-window) - (let ((owdriver-keep-driving-function (lambda (c) nil))) + (let ((owdriver-keep-driving-function nil)) (owdriver-start ,force-next-window) ,@body)) (yaxception:catch 'error e @@ -141,9 +141,8 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (defun owdriver--cleanup () (when (and owdriver-mode - (not (active-minibuffer-window)) - (functionp owdriver--keep-driving-function) - (not (funcall owdriver--keep-driving-function this-command))) + (or (not (functionp owdriver--keep-driving-function)) + (not (funcall owdriver--keep-driving-function this-command)))) (owdriver--trace "start cleanup. this-command[%s]" this-command) (owdriver-mode 0))) From 968d1d5dccfe74de3a59ff431f03544ab920f556 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Sun, 4 Jun 2023 20:02:33 +0900 Subject: [PATCH 22/24] Bump up version to 0.3.0 --- owdriver.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owdriver.el b/owdriver.el index 4555c14..472c655 100644 --- a/owdriver.el +++ b/owdriver.el @@ -5,7 +5,7 @@ ;; Author: Hiroaki Otsu ;; Keywords: convenience ;; URL: https://github.com/aki2o/owdriver -;; Version: 0.2.0 +;; Version: 0.3.0 ;; Package-Requires: ((log4e "0.2.0") (yaxception "0.2.0")) ;; This program is free software; you can redistribute it and/or modify From f816aa0283494d7349bdb03e60000741d0bf2d15 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Wed, 24 Jan 2024 18:23:17 +0900 Subject: [PATCH 23/24] Fix warnings --- owdriver.el | 84 ++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/owdriver.el b/owdriver.el index 472c655..224d4b9 100644 --- a/owdriver.el +++ b/owdriver.el @@ -1,12 +1,12 @@ -;;; owdriver.el --- Quickly perform various actions on other windows +;;; owdriver.el --- Quickly perform various actions on other windows -*- lexical-binding: t -*- ;; Copyright (C) 2014 Hiroaki Otsu ;; Author: Hiroaki Otsu ;; Keywords: convenience ;; URL: https://github.com/aki2o/owdriver -;; Version: 0.3.0 -;; Package-Requires: ((log4e "0.2.0") (yaxception "0.2.0")) +;; Version: 0.3.1 +;; Package-Requires: ((log4e "0.4.1") (yaxception "1.0.0")) ;; 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 @@ -62,7 +62,7 @@ (defcustom owdriver-keep-driving-command-prefixes '("scroll-" "next-" "previous-" "forward-" "backward-" "beginning-of-" "end-of-" "move-" "switch-to-" "xref-" "find-" "isearch-" "project-" "projectile-") "List of command prefix kept handling by `owdriver-keep-driving-p'. -This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil." +This will be ignored if set `owdriver-keep-driving-command-regexp' non-nil." :type (list 'string) :group 'owdriver) @@ -91,6 +91,35 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (defvar owdriver--keep-driving-function nil) +;;;;;;;;;; +;; Mode + +;;;###autoload +(defvar owdriver-mode-map (make-sparse-keymap)) + +;;;###autoload +(define-minor-mode owdriver-mode + "Quickly perform various actions on other windows." + :init-value nil + :lighter " OW" + :keymap owdriver-mode-map + :global t + :group 'owdriver + (if owdriver-mode + (progn + (setq owdriver--start-location `(:window ,(selected-window) :point ,(window-point), :config ,(current-window-configuration))) + (setq owdriver--keep-driving-function owdriver-keep-driving-function) + (add-hook 'pre-command-hook 'owdriver--cleanup)) + (when owdriver--start-location + (when (not (window-live-p (plist-get owdriver--start-location :window))) + (set-window-configuration (plist-get owdriver--start-location :config))) + (select-window (plist-get owdriver--start-location :window)) + (set-window-point (plist-get owdriver--start-location :window) (plist-get owdriver--start-location :point)) + (setq owdriver--start-location nil)) + (setq owdriver--keep-driving-function nil) + (remove-hook 'pre-command-hook 'owdriver--cleanup))) + + ;;;;;;;;;;;;; ;; Utility @@ -162,8 +191,9 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (featurep 'pophint) (boundp 'pophint--next-window-source) (>= (cl-loop for w in (window-list) count (funcall is-nextable-window w)) 2) - (when-let ((hint (pophint:do :source pophint--next-window-source :allwindow t))) - (pophint:hint-window hint))) + (with-no-warnings + (when-let ((hint (pophint:do :source pophint--next-window-source :allwindow t))) + (pophint:hint-window hint)))) (progn (select-window currwnd) (other-window (if reverse -1 1)) @@ -177,35 +207,6 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (string-match owdriver-keep-driving-command-regexp (symbol-name command)))) -;;;;;;;;;; -;; Mode - -;;;###autoload -(defvar owdriver-mode-map (make-sparse-keymap)) - -;;;###autoload -(define-minor-mode owdriver-mode - "Quickly perform various actions on other windows." - :init-value nil - :lighter " OW" - :keymap owdriver-mode-map - :global t - :group 'owdriver - (if owdriver-mode - (progn - (setq owdriver--start-location `(:window ,(selected-window) :point ,(window-point), :config ,(current-window-configuration))) - (setq owdriver--keep-driving-function owdriver-keep-driving-function) - (add-hook 'pre-command-hook 'owdriver--cleanup)) - (when owdriver--start-location - (when (not (window-live-p (plist-get owdriver--start-location :window))) - (set-window-configuration (plist-get owdriver--start-location :config))) - (select-window (plist-get owdriver--start-location :window)) - (set-window-point (plist-get owdriver--start-location :window) (plist-get owdriver--start-location :point)) - (setq owdriver--start-location nil)) - (setq owdriver--keep-driving-function nil) - (remove-hook 'pre-command-hook 'owdriver--cleanup))) - - ;;;;;;;;;;;;;;;;;; ;; User Command @@ -228,7 +229,7 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil (yaxception:try (setq owdriver--window (funcall owdriver-next-window-function reverse)) (select-window owdriver--window) - (lexical-let ((ov (make-overlay (point-min) (point-max)))) + (let ((ov (make-overlay (point-min) (point-max)))) (overlay-put ov 'face 'highlight) (run-with-idle-timer 0.1 nil (lambda () (when ov (delete-overlay ov)))) (owdriver--show-message "Drived window is '%s'" owdriver--window))) @@ -276,7 +277,7 @@ This value will be ignored if set `owdriver-keep-driving-command-regexp' non-nil "Define the command for driving `owdriver--window' from COMMAND. The command named `owdriver-do-COMMAND' is defined by this function. -BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is no need." +BODY is sexp. If nil, COMMAND will be called." (declare (indent 2)) (let* ((body (or body `((call-interactively ',command)))) (cmdnm (symbol-name command)) @@ -293,7 +294,7 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n ,@body))) ;;;###autoload (defun ,fcommand () - ,(format "Do `%s' in `owdriver--window' with `owdriver-next-window'." cmdnm) + ,(format "Do `%s' in `owdriver--window'\nwith `owdriver-next-window'." cmdnm) (interactive) (owdriver--with-selected-window ,fcommand t ,@body))))) @@ -319,8 +320,11 @@ BODY is sexp. If COMMAND is used in `owdriver--window' actually, this value is n ;; Patch for Emacs 26.1 (when (>= emacs-major-version 26) (defun owdriver--patch-on-26-1 () - "Function to patch the trouble on GNU Emacs 26.1 (build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 Version 10.10.5 (Build 14F2511)) of 2018-05-31, -which emacs seems to not refresh a screen when `scroll-left', `scroll-right' with `with-selected-window'." + "Function to patch the trouble on GNU Emacs 26.1 +(build 1, x86_64-apple-darwin14.5.0, NS appkit-1348.17 Version 10.10.5 +(Build 14F2511)) of 2018-05-31, +which emacs seems to not refresh a screen +when `scroll-left', `scroll-right' with `with-selected-window'." (let ((wnd (get-buffer-window)) (pt (with-selected-window owdriver--window (point)))) (select-window owdriver--window) From e9c4650e9d4a476bb90c3e04f5dbc1821c26ea35 Mon Sep 17 00:00:00 2001 From: Hiroaki Otsu Date: Wed, 24 Jan 2024 18:24:25 +0900 Subject: [PATCH 24/24] Fix .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 433da84..96a152a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .cask *.elc +*-autoloads.el