* lisp/url/url-handlers.el (url-http-parse-response): Remove unused autoload.
[bpt/emacs.git] / lisp / dframe.el
index dba8936..90edacb 100644 (file)
@@ -1,7 +1,6 @@
-;;; dframe --- dedicate frame support modes
+;;; dframe --- dedicate frame support modes  -*- lexical-binding:t -*-
 
-;;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;;    2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: file, tags, tools
@@ -83,7 +82,7 @@
 ;;       c) If successful (your -frame variable has a value), call
 ;;          timer setup if applicable.
 ;;   your-frame-reposition- -- Function to call from after-create-hook to
-;;     reposition your frame with `dframe-repsoition-frame'.
+;;     reposition your frame with `dframe-reposition-frame'.
 ;;   your-mode -- Set up the major mode of the buffer for your app.
 ;;     Set these variables: dframe-track-mouse-function,
 ;;                          dframe-help-echo-function,
@@ -97,7 +96,7 @@
 ;;   dframe-track-mouse, dframe-help-echo-function --
 ;;    These variables need to be set to functions that display info
 ;;    based on the mouse's position.
-;;   Text propert 'help-echo, set to `dframe-help-echo', which will
+;;   Text property 'help-echo, set to `dframe-help-echo', which will
 ;;    call `dframe-help-echo-function'.
 ;;   Have a `-click' function, it can call `dframe-quick-mouse' for
 ;;    positioning.  If the variable `dframe-power-click' is non-nil,
@@ -137,7 +136,7 @@ This is nil for terminals, since updating a frame in a terminal
 is not useful to the user.")
 
 (defcustom dframe-update-speed
-  (if (featurep 'xemacs) 2             ; 1 is too obrusive in XEmacs
+  (if (featurep 'xemacs) 2             ; 1 is too obtrusive in XEmacs
     1)
   "Idle time in seconds needed before dframe will update itself.
 Updates occur to allow dframe to display directory information
@@ -158,22 +157,22 @@ selected frame and the focus will change to that frame."
   :type 'hook)
 
 (defvar dframe-track-mouse-function nil
-  "*A function to call when the mouse is moved in the given frame.
+  "A function to call when the mouse is moved in the given frame.
 Typically used to display info about the line under the mouse.")
 (make-variable-buffer-local 'dframe-track-mouse-function)
 
 (defvar dframe-help-echo-function nil
-  "*A function to call when help-echo is used in newer versions of Emacs.
+  "A function to call when help-echo is used in newer versions of Emacs.
 Typically used to display info about the line under the mouse.")
 (make-variable-buffer-local 'dframe-help-echo-function)
 
 (defvar dframe-mouse-click-function nil
-  "*A function to call when the mouse is clicked.
+  "A function to call when the mouse is clicked.
 Valid clicks are mouse 2, our double mouse 1.")
 (make-variable-buffer-local 'dframe-mouse-click-function)
 
 (defvar dframe-mouse-position-function nil
-  "*A function to call to position the cursor for a mouse click.")
+  "A function to call to position the cursor for a mouse click.")
 (make-variable-buffer-local 'dframe-mouse-position-function)
 
 (defvar dframe-power-click nil
@@ -222,7 +221,7 @@ Local to those buffers, as a function called that created it.")
     (define-key map [mouse-2] 'dframe-click)
     ;; This is the power click for new frames, or refreshing a cache
     (define-key map [S-mouse-2] 'dframe-power-click)
-    ;; This adds a small unecessary visual effect
+    ;; This adds a small unnecessary visual effect
     ;;(define-key map [down-mouse-2] 'dframe-quick-mouse)
 
     (define-key map [down-mouse-3] 'dframe-popup-kludge)
@@ -244,6 +243,9 @@ Local to those buffers, as a function called that created it.")
   "Return non-nil if FRAME is currently available."
   (and frame (frame-live-p frame) (frame-visible-p frame)))
 
+(defvar x-sensitive-text-pointer-shape)
+(defvar x-pointer-shape)
+
 (defun dframe-frame-mode (arg frame-var cache-var buffer-var frame-name
                              local-mode-fn
                              &optional
@@ -260,9 +262,15 @@ 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 are hooks to run when deleting a frame.
-POPUP-HOOK are hooks to run before showing a frame.
-CREATE-HOOK are hooks to run after creating a frame."
+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)))
@@ -271,7 +279,7 @@ CREATE-HOOK are hooks to run after creating a frame."
   ;; turn the frame off on neg number
   (if (and (numberp arg) (< arg 0))
       (progn
-       (run-hooks 'delete-hook)
+       (run-hooks delete-hook)
        (if (and (symbol-value frame-var)
                 (frame-live-p (symbol-value frame-var)))
            (progn
@@ -280,7 +288,7 @@ CREATE-HOOK are hooks to run after creating a frame."
        (set frame-var nil))
     ;; Set this as our currently attached frame
     (setq dframe-attached-frame (selected-frame))
-    (run-hooks 'popup-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)
@@ -332,15 +340,15 @@ CREATE-HOOK are hooks to run after creating a frame."
       (setq 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)
-                                              (setq ,buffer-var nil)
-                                              )))))
+      (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
@@ -397,7 +405,7 @@ CREATE-HOOK are hooks to run after creating a frame."
          (switch-to-buffer (symbol-value buffer-var))
          (set-window-dedicated-p (selected-window) t))
        ;; Run hooks (like reposition)
-       (run-hooks 'create-hook)
+       (run-hooks create-hook)
        ;; Frame name
        (if (and (or (null window-system) (eq window-system 'pc))
                 (fboundp 'set-frame-name))
@@ -430,7 +438,8 @@ a cons cell indicating a position of the form (LEFT . TOP)."
   (unless (or (not window-system) (eq window-system 'pc))
     (let* ((pfx (dframe-frame-parameter parent-frame 'left))
           (pfy (dframe-frame-parameter parent-frame 'top))
-          (pfw (frame-pixel-width parent-frame))
+          (pfw (+ (tool-bar-pixel-width parent-frame)
+                  (frame-pixel-width parent-frame)))
           (pfh (frame-pixel-height parent-frame))
           (nfw (frame-pixel-width new-frame))
           (nfh (frame-pixel-height new-frame))
@@ -459,7 +468,7 @@ a cons cell indicating a position of the form (LEFT . TOP)."
                      (- (x-display-pixel-height) (car (cdr pfy)) pfh)
                    (car (cdr pfy)))))
       (cond ((eq location 'right)
-            (setq newleft (+ pfx pfw 5)
+            (setq newleft (+ pfx pfw 10)
                   newtop pfy))
            ((eq location 'left)
             (setq newleft (- pfx 10 nfw)
@@ -471,7 +480,7 @@ a cons cell indicating a position of the form (LEFT . TOP)."
                   ;; extra 10 is just dressings for window
                   ;; decorations.
                   (let* ((left-guess (- pfx 10 nfw))
-                         (right-guess (+ pfx pfw 5))
+                         (right-guess (+ pfx pfw 10))
                          (left-margin left-guess)
                          (right-margin (- (x-display-pixel-width)
                                           right-guess 5 nfw)))
@@ -503,7 +512,7 @@ a cons cell indicating a position of the form (LEFT . TOP)."
                               (list (cons 'left newleft)
                                     (cons 'top newtop))))))
 
-(defun dframe-reposition-frame-xemacs (new-frame parent-frame location)
+(defun dframe-reposition-frame-xemacs (_new-frame _parent-frame _location)
   "Move NEW-FRAME to be relative to PARENT-FRAME.
 LOCATION can be one of 'random, 'left-right, or 'top-bottom."
   ;; Not yet implemented
@@ -513,15 +522,15 @@ LOCATION can be one of 'random, 'left-right, or 'top-bottom."
 (defun dframe-needed-height (&optional frame)
   "The needed height for the tool bar FRAME (in characters)."
   (or frame (setq frame (selected-frame)))
-  ;; The 1 is the missing modeline/minibuffer
+  ;; The 1 is the missing mode line or minibuffer
   (+ 1 (/ (frame-pixel-height frame)
          ;; This obscure code avoids a byte compiler warning in Emacs.
          (let ((f 'face-height))
            (funcall f 'default frame)))))
 
 (defun dframe-detach (frame-var cache-var buffer-var)
-  "Detatch the frame in symbol FRAME-VAR.
-CACHE-VAR and BUFFER-VAR are symbols as in `dframe-frame-mode'"
+  "Detach the frame in symbol FRAME-VAR.
+CACHE-VAR and BUFFER-VAR are symbols as in `dframe-frame-mode'."
   (with-current-buffer (symbol-value buffer-var)
     (rename-buffer (buffer-name) t)
     (let ((oldframe (symbol-value frame-var)))
@@ -597,13 +606,12 @@ Argument E is the event deleting the frame."
 
 ;;; Utilities
 ;;
-(defun dframe-get-focus (frame-var activator &optional hook)
+(defun dframe-get-focus (frame-var activator)
   "Change frame focus to or from a dedicated frame.
 If the selected frame is not in the symbol FRAME-VAR, then FRAME-VAR
 frame is selected.  If the FRAME-VAR is active, then select the
 attached frame.  If FRAME-VAR is nil, ACTIVATOR is called to
-created it.  HOOK is an optional argument of hooks to run when
-selecting FRAME-VAR."
+created it."
   (interactive)
   (if (eq (selected-frame) (symbol-value frame-var))
       (if (frame-live-p dframe-attached-frame)
@@ -614,9 +622,7 @@ selecting FRAME-VAR."
     ;; go there
     (select-frame (symbol-value frame-var))
     )
-  (other-frame 0)
-  ;; If updates are off, then refresh the frame (they want it now...)
-  (run-hooks 'hook))
+  (other-frame 0))
 
 
 (defun dframe-close-frame ()
@@ -632,7 +638,7 @@ selecting FRAME-VAR."
 FRAME-VAR is the variable storing the currently active dedicated frame.
 If the current frame's buffer uses DESIRED-MAJOR-MODE, then use that frame."
   (if (not (eq (selected-frame) (symbol-value frame-var)))
-      (if (and (eq major-mode 'desired-major-mode)
+      (if (and (eq major-mode desired-major-mode)
               (get-buffer-window (current-buffer))
               (window-frame (get-buffer-window (current-buffer))))
          (window-frame (get-buffer-window (current-buffer)))
@@ -678,7 +684,7 @@ Optionally select that frame if necessary."
   "Non-nil means that `dframe-message' should just return a string.")
 
 (defun dframe-message (fmt &rest args)
-  "Like message, but for use in a dedicated frame.
+  "Like `message', but for use in a dedicated frame.
 Argument FMT is the format string, and ARGS are the arguments for message."
   (save-selected-window
     (if dframe-suppress-message-flag
@@ -713,18 +719,17 @@ Argument PROMPT is the prompt to use."
 (defvar dframe-client-functions nil
   "List of client functions using the dframe timer.")
 
-(defun dframe-set-timer (timeout fn &optional null-on-error)
+(defun dframe-set-timer (timeout fn &optional _null-on-error)
   "Apply a timer with TIMEOUT, to call FN, or remove a timer if TIMEOUT is nil.
-TIMEOUT is the number of seconds until the dframe controled program
+TIMEOUT is the number of seconds until the dframe controlled program
 timer is called again.  When TIMEOUT is nil, turn off all timeouts.
 This function must be called from the buffer belonging to the program
-who requested the timer.
-If NULL-ON-ERROR is a symbol, set it to nil if we cannot create a timer."
+who requested the timer.  NULL-ON-ERROR is ignored."
   ;; First, fix up our list of client functions
   (if timeout
       (add-to-list 'dframe-client-functions fn)
     (setq dframe-client-functions (delete fn dframe-client-functions)))
-  ;; Now decided what to do about the timout.
+  ;; Now decided what to do about the timeout.
   (if (or
        ;; We have a timer, restart the timer with the new time.
        timeout
@@ -732,9 +737,9 @@ If NULL-ON-ERROR is a symbol, set it to nil if we cannot create a timer."
        ;; functions are left, shut er down.
        (and dframe-timer (not timeout) dframe-client-functions))
       ;; Only call the low level function if we are changing the state.
-      (dframe-set-timer-internal timeout null-on-error)))
+      (dframe-set-timer-internal timeout)))
 
-(defun dframe-set-timer-internal (timeout &optional null-on-error)
+(defun dframe-set-timer-internal (timeout &optional _null-on-error)
   "Apply a timer with TIMEOUT to call the dframe timer manager."
   (when dframe-timer
     (if (featurep 'xemacs)
@@ -753,9 +758,8 @@ If NULL-ON-ERROR is a symbol, set it to nil if we cannot create a timer."
 Evaluates all cached timer functions in sequence."
   (let ((l dframe-client-functions))
     (while (and l (sit-for 0))
-      (condition-case er
-         (funcall (car l))
-       (error (message "DFRAME TIMER ERROR: %S" er)))
+      (with-demoted-errors "DFRAME TIMER ERROR: %S"
+       (funcall (car l)))
       (setq l (cdr l)))))
 
 ;;; Menu hacking for mouse-3
@@ -783,8 +787,8 @@ Must be bound to EVENT."
               (popup-mode-menu event)
             (goto-char (event-closest-point event))
             (beginning-of-line)
-            (forward-char (min 5 (- (save-excursion (end-of-line) (point))
-                                    (save-excursion (beginning-of-line) (point)))))
+            (forward-char (min 5 (- (line-end-position)
+                                    (line-beginning-position))))
             (popup-mode-menu))
           ;; Wait for menu to bail out.  `popup-mode-menu' (and other popup
           ;; menu functions) return immediately.
@@ -838,7 +842,7 @@ Must be bound to event E."
   (if dframe-track-mouse-function
       (funcall dframe-track-mouse-function event)))
 
-(defun dframe-help-echo (window &optional buffer position)
+(defun dframe-help-echo (_window &optional buffer position)
   "Display help based context.
 The context is in WINDOW, viewing BUFFER, at POSITION.
 BUFFER and POSITION are optional because XEmacs doesn't use them."
@@ -933,7 +937,7 @@ redirected into a window on the attached frame."
         (mapcar (function (lambda (hook) (funcall hook buffer)))
                 temp-buffer-show-hook))))
 
-(defun dframe-hack-buffer-menu (e)
+(defun dframe-hack-buffer-menu (_e)
   "Control mouse 1 is buffer menu.
 This hack overrides it so that the right thing happens in the main
 Emacs frame, not in the dedicated frame.
@@ -967,7 +971,7 @@ broken because of the dedicated frame."
       (switch-to-buffer buffer)
     (call-interactively 'switch-to-buffer nil nil)))
 
-;; XEmacs: this can be implemented using modeline keymaps, but there
+;; XEmacs: this can be implemented using mode line keymaps, but there
 ;; is no use, as we have horizontal scrollbar (as the docstring
 ;; hints.)
 (defun dframe-mouse-hscroll (e)
@@ -985,10 +989,8 @@ mode-line.  This is only useful for non-XEmacs."
          ((> click-col (- (window-width) 5))
           (scroll-right 2))
          (t (dframe-message
-             "Click on the edge of the modeline to scroll left/right")))
-    ))
+             "Click on the edge of the mode line to scroll left/right")))))
 
 (provide 'dframe)
 
-;; arch-tag: df9b91b6-e85e-4a76-a02e-b3cb5b686bd4
 ;;; dframe.el ends here