Function: dframe-frame-mode

dframe-frame-mode is a byte-compiled function defined in dframe.el.gz.

Signature

(dframe-frame-mode ARG FRAME-VAR CACHE-VAR BUFFER-VAR FRAME-NAME LOCAL-MODE-FN &optional PARAMETERS DELETE-HOOK POPUP-HOOK CREATE-HOOK)

Documentation

Manage a frame for an application, enabling it when ARG is positive.

FRAME-VAR is a variable used to cache the frame being used. This frame is either resurrected, hidden, killed, etc based on the value. CACHE-VAR is a variable used to cache a cached frame. BUFFER-VAR is a variable used to cache the buffer being used in dframe. This buffer will have dframe-frame-mode run on it. FRAME-NAME is the name of the frame to create. LOCAL-MODE-FN is the function used to call this one. PARAMETERS are frame parameters to apply to this dframe. DELETE-HOOK is a hook to run when deleting a frame. POPUP-HOOK is a hook to run before showing a frame. CREATE-HOOK is a hook to run after creating a frame.

Source Code

;; Defined in /usr/src/emacs/lisp/dframe.el.gz
(defun dframe-frame-mode (arg frame-var cache-var buffer-var frame-name
			      local-mode-fn
			      &optional
			      parameters
			      delete-hook popup-hook create-hook
			      )
  "Manage a frame for an application, enabling it when ARG is positive.
FRAME-VAR is a variable used to cache the frame being used.
This frame is either resurrected, hidden, killed, etc based on
the value.
CACHE-VAR is a variable used to cache a cached frame.
BUFFER-VAR is a variable used to cache the buffer being used in dframe.
This buffer will have `dframe-frame-mode' run on it.
FRAME-NAME is the name of the frame to create.
LOCAL-MODE-FN is the function used to call this one.
PARAMETERS are frame parameters to apply to this dframe.
DELETE-HOOK is a hook to run when deleting a frame.
POPUP-HOOK is a hook to run before showing a frame.
CREATE-HOOK is a hook to run after creating a frame."
  (let ((conv-hook (lambda (val)
                     (let ((sym (make-symbol "hook")))
                       (set sym val) sym))))
    (if (consp delete-hook) (setq delete-hook (funcall conv-hook delete-hook)))
    (if (consp create-hook) (setq create-hook (funcall conv-hook create-hook)))
    (if (consp popup-hook)  (setq popup-hook  (funcall conv-hook popup-hook))))
  ;; toggle frame on and off.
  (if (not arg) (if (dframe-live-p (symbol-value frame-var))
		    (setq arg -1) (setq arg 1)))
  ;; Make sure the current buffer is set.
  (set-buffer (symbol-value buffer-var))
  ;; turn the frame off on neg number
  (if (and (numberp arg) (< arg 0))
      (progn
	(run-hooks delete-hook)
	(if (and (symbol-value frame-var)
		 (frame-live-p (symbol-value frame-var)))
	    (progn
	      (set cache-var (symbol-value frame-var))
	      (make-frame-invisible (symbol-value frame-var))))
	(set frame-var nil))
    ;; Set this as our currently attached frame
    (setq dframe-attached-frame (selected-frame))
    (run-hooks 'dframe-setup-hook)
    (run-hooks popup-hook)
    ;; Updated the buffer passed in to contain all the hacks needed
    ;; to make it work well in a dedicated window.
    (with-current-buffer (symbol-value buffer-var)
      ;; Declare this buffer a dedicated frame
      (setq dframe-controlled local-mode-fn)

      ;; Enable mouse tracking in emacs
      (if dframe-track-mouse-function
          (setq-local track-mouse t)) ;this could be messy.

      ;; Override `temp-buffer-show-hook' so that help and such
      ;; put their stuff into a frame other than our own.
      ;; Correct use of `temp-buffer-show-function': Bob Weiner
      (if (and (boundp 'temp-buffer-show-hook)
	       (boundp 'temp-buffer-show-function))
	  ;; FIXME: Doesn't this get us into an inf-loop when the
          ;; `temp-buffer-show-function' runs `temp-buffer-show-hook'
          ;; (as is normally the case)?
          (setq-local temp-buffer-show-hook temp-buffer-show-function))
      (setq-local temp-buffer-show-function 'dframe-temp-buffer-show-function)
      ;; If this buffer is killed, we must make sure that we destroy
      ;; the frame the dedicated window is in.
      (add-hook 'kill-buffer-hook (lambda ()
                                    (let ((skilling (boundp 'skilling)))
                                      (if skilling
                                          nil
                                        (if dframe-controlled
                                            (progn
                                              (funcall dframe-controlled -1)
                                              (set buffer-var nil)
                                              )))))
		t t))
    ;; Get the frame to work in
    (if (frame-live-p (symbol-value cache-var))
	(progn
	  (set frame-var (symbol-value cache-var))
	  (make-frame-visible (symbol-value frame-var))
	  (select-frame (symbol-value frame-var))
	  (set-window-dedicated-p (selected-window) nil)
	  (unless (eq (current-buffer) (symbol-value buffer-var))
            ;; To avoid that 'switch-to-buffer-obey-display-actions'
            ;; butts in, use plain 'set-window-buffer' (Bug#37840).
            (set-window-buffer nil (symbol-value buffer-var)))
	  (set-window-dedicated-p (selected-window) t)
	  (raise-frame (symbol-value frame-var))
	  )
      (if (frame-live-p (symbol-value frame-var))
	  (raise-frame (symbol-value frame-var))
	(set frame-var
             (let* ((mh (frame-parameter dframe-attached-frame
                                         'menu-bar-lines))
		    (paramsa
		     ;; Only add a guessed height if one is not specified
		     ;; in the input parameters.
		     (if (assoc 'height parameters)
			 parameters
		       (append
			parameters
			(list (cons 'height (+ (or mh 0) (frame-height)))))))
		    (params
		     ;; Only add a guessed width if one is not specified
		     ;; in the input parameters.
		     (if (assoc 'width parameters)
			 paramsa
		       (append
			paramsa
			(list (cons 'width (frame-width))))))
		    (frame
		     (if (not (eq window-system 'x))
			 (make-frame params)
		       (let ((x-pointer-shape x-pointer-top-left-arrow)
			     (x-sensitive-text-pointer-shape
			      x-pointer-hand2))
			 (make-frame params)))))
	       frame))
	;; Put the buffer into the frame
	(save-excursion
	  (select-frame (symbol-value frame-var))
          ;; To avoid that 'switch-to-buffer-obey-display-actions'
          ;; butts in, use plain 'set-window-buffer' (Bug#37840).
	  (set-window-buffer nil (symbol-value buffer-var))
	  (set-window-dedicated-p (selected-window) t))
	;; Run hooks (like reposition)
	(run-hooks create-hook)
	;; Frame name
	(if (and (or (null window-system) (eq window-system 'pc))
		 (fboundp 'set-frame-name))
	    (save-window-excursion
	      (select-frame (symbol-value frame-var))
	      (set-frame-name frame-name)))
	;; On a terminal, raise the frame or the user will
	;; be confused.
	(if (not window-system)
	    (select-frame (symbol-value frame-var)))))))