You may find the attached file useful.

I wrote this to support my own work habits - emacs is used as a server,
and this setup allows

me to switch to a frame that displays a certain buffer by simply
switching buffers, even if it's on a different
workspace (which seems to be the intended behavior under desktop
managers such as kde).


Note that I'm using emacs/ion snapshots that are at least 6 months
old... so it may not work

out of the box.


Enjoy.

Avi.


Jeremy Hankins wrote:

> When I have multiple emacs frames (i.e., ion clients) open showing
> different buffers I can switch from frame to frame from within emacs by
> switching buffers.  Presumably this means that emacs is sending a raise
> event, but I don't really know X, so I may not be understanding what's
> happening.
>
> At any rate, when the target emacs frame (ion client) isn't visible the
> mouse warps but the emacs frame doesn't become visible.  Focus ends up
> on wherever the mouse happens to be, which may be something entirely
> unrelated.  Interestingly, the mouse warping occurs even if after
> running ioncore.set{warp=false}.
>
>   

;;; ionflux.el -- emacs integration with ion3 wm (raise window etc.)
;;; by Avi Rozen <[EMAIL PROTECTED]>

;;; To install:
;;; - install ion3
;;; - install ionflux
;;; - put this file somewhere visible to emacs
;;; - add the following line to your emacs init code (e.g. .emacs):
;;;   (require 'ionflux)

;;; tested under emacs cvs snapshot 4/06 with ion3 darcs snapshot from 1/06 
;;;
;;; FIXME: add license here (GPL)
;;; FIXME: the lua code will break under lua 5.1 (for loop syntax)
;;; FIXME: test with/port to older/newer version of emacs (maybe also xemacs) - 
;;; FIXME: test with/port to newer version of ion3

(defconst ionflux-available-p
  (and (eq window-system 'x)
       (= (call-process-shell-command "ionflux" nil nil nil nil "-e" "\"return ioncore.version()\"") 0))
  "ionflux available flag.")

(defun ionflux-raise-lower-frame-xid (frame-xid raise)
  "Use Ion3 WM's ionflux utility to raise/lower frame with a given XID.
Frame is raised if RAISE is non-nil, and lowered otherwise."
  (if (and ionflux-available-p
	   (stringp frame-xid))
      (call-process-shell-command
       "ionflux"
       nil
       nil
       nil
       nil
       "-e"
       (concat "\""
	       "local cwin = nil; "
	       "for _, w in ioncore.clientwin_list() do "
	       "  if (w:xid() == " frame-xid ") then "
	       "     cwin = w; "
	       "     break; "
	       "  end; "
	       "end; "
	       "if (cwin ~= nil) then "
	       (when raise "  cwin:goto(); ")
	       "  local w = ioncore.find_manager(cwin,\\\"WFloatWS\\\"); "
	       "  local f = ioncore.find_manager(cwin,\\\"WFrame\\\"); "
	       "  if (w~=nil and f~=nil) then "
	       (if raise
		   "     WFloatWS.raise(w,f); "
		   "     WFloatWS.lower(w,f); "
		   )		 
	       "  end; "
	       "end"
	       "\""))
    0))

(ad-define-subr-args 'raise-frame '(&optional frame))
(defadvice raise-frame (after ionflux-raise-frame activate)
  "Raise frame on Ion3 WM."
  (when ionflux-available-p
    (let ((frame-xid (frame-parameter frame 'outer-window-id)))
      (when frame-xid
	(ionflux-raise-lower-frame-xid frame-xid t))))
  ad-return-value)

(ad-define-subr-args 'lower-frame '(&optional frame))
(defadvice lower-frame (after ionflux-lower-frame activate)
  "Lower frame on Ion3 WM."
  (when ionflux-available-p
    (let ((frame-xid (frame-parameter frame 'outer-window-id)))
      (when frame-xid
	(ionflux-raise-lower-frame-xid frame-xid nil))))
  ad-return-value)

(ad-define-subr-args 'display-buffer '(buffer &optional not-this-window frame))
(defadvice display-buffer (after ionflux-display-buffer activate)
  "Raise selected frame on Ion3 WM."
  (when ionflux-available-p
    (let* ((current-window (get-buffer-window buffer 0))
	   (current-frame (if current-window
			      (window-frame current-window)
			    nil))
	   (frame-xid (frame-parameter current-frame 'outer-window-id)))
      (when frame-xid
	(ionflux-raise-lower-frame-xid frame-xid t))))
  ad-return-value)

(ad-define-subr-args 'yes-or-no-p '(prompt))
(defadvice yes-or-no-p (before ionflux-yes-or-no-p activate)
  "Raise frame when asking on Ion3 WM."
  (when ionflux-available-p
    (let ((frame-xid (frame-parameter nil 'outer-window-id)))
      (when frame-xid
	(ionflux-raise-lower-frame-xid frame-xid t)))))

(ad-define-subr-args 'y-or-n-p '(prompt))
(defadvice y-or-n-p (before ionflux-y-or-n-p activate)
  "Raise frame when asking on Ion3 WM."
  (when ionflux-available-p
    (let ((frame-xid (frame-parameter nil 'outer-window-id)))
      (when frame-xid
	(ionflux-raise-lower-frame-xid frame-xid t)))))

(provide 'ionflux)

Reply via email to