]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/other-frame-window/other-frame-window.el
Fix some quoting problems in doc strings
[gnu-emacs-elpa] / packages / other-frame-window / other-frame-window.el
index 4b7f6b62b2519b205f149dcad9bca00a26873779..979d18f9908e9733f59c94a79fe282397e257dd5 100755 (executable)
@@ -5,7 +5,7 @@
 ;; Author: Stephen Leake <stephen_leake@member.fsf.org>
 ;; Maintainer: Stephen Leake <stephen_leake@member.fsf.org>
 ;; Keywords: frame window
-;; Version: 1.0.1
+;; Version: 1.0.2
 ;; Package-Requires: ((emacs "24.4"))
 ;;
 ;; This file is part of GNU Emacs.
 
 ;;;; 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:
 
 
 (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."
+  "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)))))
 
   "Show BUFFER in another window in the current frame,
 creating new window if needed and allowed.
 If successful, return window; else return nil.
-Intended for 'display-buffer-overriding-action'."
+Intended for `display-buffer-overriding-action'."
   ;; Reset for next display-buffer call.  Normally, this is taken care
   ;; of by ofw--reset-prefix, but we do it here in case the user does
   ;; two ofw prefixed commands consecutively.
@@ -144,14 +161,14 @@ Intended for 'display-buffer-overriding-action'."
 (defun ofw-display-buffer-other-frame (buffer alist)
   "Show BUFFER in another frame, creating a new frame if needed.
 If successful, return window; else return nil.
-Intended for 'display-buffer-overriding-action'."
+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'."
+  "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 <tab> 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))))