X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/b0039dd1f382edcd722f6c1c7194867538831d32..59010d078e49cd04d65c3fc306b01cfc2163516a:/packages/other-frame-window/other-frame-window.el diff --git a/packages/other-frame-window/other-frame-window.el b/packages/other-frame-window/other-frame-window.el index 4b7f6b62b..2427ce659 100755 --- a/packages/other-frame-window/other-frame-window.el +++ b/packages/other-frame-window/other-frame-window.el @@ -5,7 +5,7 @@ ;; Author: Stephen Leake ;; Maintainer: Stephen Leake ;; Keywords: frame window -;; Version: 1.0.1 +;; Version: 1.0.2 ;; Package-Requires: ((emacs "24.4")) ;; ;; This file is part of GNU Emacs. @@ -54,9 +54,10 @@ ;;;; Todo: -;; - Make the `C-x 7' prefix appear in the echo area. -;; - `C-x 7 C-h' should display the transient map. -;; - `C-x 7 C-u foo' should pass both prefixes to `foo'. +;; - Pay attention to bindings added to ctl-x-4-map and ctl-x-5-map +;; - Should `C-x 7 C-h' display the transient map? +;; - `C-x 7 C-h k f' should show `find-file' rather than `self-insert-command'. +;; This should probably be fixed in set-transient-map. ;;; Code: @@ -88,26 +89,42 @@ (defun ofw--set-prefix (func) "Add ofw prefix function FUNC." + (ofw-delete-from-overriding) (let ((functions (car display-buffer-overriding-action)) (attrs (cdr display-buffer-overriding-action))) (push func functions) (setq display-buffer-overriding-action (cons functions attrs)) - ;; Make sure the next pre-command-hook doesn't immediately set - ;; display-buffer-overriding-action back to nil. - (setq ofw--just-set t) ;; C-u C-x 7 foo should pass C-u to foo, not to C-x 7, so ;; pass the normal prefix to the next command. - ;; FIXME: This should be done by all prefix commands and for all kinds of - ;; prefixes, so that C-x 7 C-u foo works as well! - (setq prefix-arg current-prefix-arg) + (if (fboundp 'prefix-command-preserve-state) + (prefix-command-preserve-state) + ;; Make sure the next pre-command-hook doesn't immediately set + ;; display-buffer-overriding-action back to nil. + (setq ofw--just-set t) + (setq prefix-arg current-prefix-arg)) (set-transient-map ofw-transient-map))) +(defun ofw--echo-keystrokes () + (let ((funs (car display-buffer-overriding-action))) + (cond + ((memq #'ofw-display-buffer-other-frame funs) "[other-frame]") + ((memq #'ofw-display-buffer-other-window funs) "[other-window]")))) + +(when (boundp 'prefix-command-echo-keystrokes-functions) + (add-hook 'prefix-command-echo-keystrokes-functions + #'ofw--echo-keystrokes)) + +(defun ofw--preserve-state () (setq ofw--just-set t)) +(when (boundp 'prefix-command-preserve-state-hook) + (add-hook 'prefix-command-preserve-state-hook + #'ofw--preserve-state)) + (defun ofw-delete-from-overriding () "Remove ourselves from 'display-buffer-overriding-action' action list, if present." (let ((functions (car display-buffer-overriding-action)) (attrs (cdr display-buffer-overriding-action))) - (setq functions (delq #'ofw-display-buffer-other-frame - (delq #'ofw-display-buffer-other-window functions))) + (setq functions (remq #'ofw-display-buffer-other-frame + (remq #'ofw-display-buffer-other-window functions))) (setq display-buffer-overriding-action (when (or functions attrs) (cons functions attrs))))) @@ -148,10 +165,10 @@ Intended for 'display-buffer-overriding-action'." ;; Reset for next display-buffer call. (ofw-delete-from-overriding) + ;; IMPROVEME: prompt for a frame if more than 2 (or (display-buffer-use-some-frame buffer alist) (display-buffer-pop-up-frame buffer alist))) -;; FIXME: use defadvice for Emacs 24.3 (defun ofw-switch-to-buffer-advice (orig-fun buffer &optional norecord force-same-window) "Change `switch-to-buffer' to call `pop-to-buffer'. @@ -161,14 +178,9 @@ This allows `switch-to-buffer' to respect `ofw-other-window', (pop-to-buffer buffer (list #'display-buffer-same-window) norecord) (funcall orig-fun buffer norecord force-same-window))) -;; FIXME: use defadvice for Emacs 24.3 (defun ofw--suspend-and-restore (orig-func &rest args) "Call ORIG-FUNC without any ofw actions on 'display-buffer-overriding-action'." (let ((display-buffer-overriding-action display-buffer-overriding-action)) - ;; FIXME: ofw-delete-from-overriding operates destructively, so the - ;; subsequent "restore" step only works if our ofw actions were all at the - ;; very beginning display-buffer-overriding-action (in which case `delq' - ;; happens not to be destructive). (ofw-delete-from-overriding) (apply orig-func args))) @@ -211,6 +223,7 @@ Point stays in moved buffer." (setq ofw--just-set nil) (ofw-delete-from-overriding))) +;;;###autoload (define-minor-mode other-frame-window-mode "Minor mode for other frame/window buffer placement. Enable mode if ARG is positive." @@ -235,23 +248,12 @@ Enable mode if ARG is positive." (setq display-buffer-base-action (cons functions attrs))) ;; Change switch-to-buffer to use display-buffer - (if (fboundp 'advice-add) ;Emacs≥24.4 - (advice-add 'switch-to-buffer :around #'ofw-switch-to-buffer-advice) - ;; FIXME: `ad-activate' affects all pieces of advice of that - ;; function, which is not what we want! - ;; (ad-activate 'switch-to-buffer) - ) + (advice-add 'switch-to-buffer :around #'ofw-switch-to-buffer-advice) ;; Completing-read pops up a buffer listing completions; ;; that should not respect or consume ;; ofw-frame-window-prefix-arg. - (if (fboundp 'advice-add) - (advice-add 'read-from-minibuffer - :around #'ofw--suspend-and-restore) - ;; FIXME: `ad-activate' affects all pieces of advice of that - ;; function, which is not what we want! - ;; (ad-activate 'read-from-minibuffer) - ) + (advice-add 'read-from-minibuffer :around #'ofw--suspend-and-restore) ) ;; else disable @@ -309,7 +311,7 @@ that allows the selected frame)." (defun ofw-dwim--frame-p () "Return non-nil if the prefix is for \"other-frame\" rather than window." - ;; FIXME: Comparing functions is ugly/hackish! + ;; IMPROVEME: Comparing functions is ugly/hackish! (memq #'ofw-display-buffer-other-frame (car display-buffer-overriding-action))) @@ -329,7 +331,7 @@ that allows the selected frame)." "Show current buffer in other frame or window." (interactive) (if (ofw-dwim--frame-p) - ;; FIXME: This is the old C-x 5 2 behavior, but maybe it should just use + ;; IMPROVEME: This is the old C-x 5 2 behavior, but maybe it should just use ;; display-buffer instead! (call-interactively #'make-frame-command) (display-buffer (current-buffer))))