]> code.delx.au - gnu-emacs/blobdiff - lisp/help-at-pt.el
* lisp/net/tramp-sh.el (tramp-methods) <doas>: Add. (Bug#22542)
[gnu-emacs] / lisp / help-at-pt.el
index d6ac6ec3fdcaf72a41378592cbf9343650824dba..b90be5a3efea41161015d6e622440930d4ddd924 100644 (file)
@@ -1,16 +1,16 @@
 ;;; help-at-pt.el --- local help through the keyboard
 
-;; Copyright (C) 2003 Free Software Foundation, Inc.
+;; Copyright (C) 2003-2016 Free Software Foundation, Inc.
 
 ;; Author: Luc Teirlinck <teirllm@auburn.edu>
 ;; Keywords: help
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -53,7 +51,7 @@
 (defgroup help-at-pt nil
   "Features for displaying local help."
   :group 'help
-  :version "21.4")
+  :version "22.1")
 
 ;;;###autoload
 (defun help-at-pt-string (&optional kbd)
@@ -63,20 +61,25 @@ property, or nil, is returned.
 If KBD is non-nil, `kbd-help' is used instead, and any
 `help-echo' property is ignored.  In this case, the return value
 can also be t, if that is the value of the `kbd-help' property."
-  (let* ((prop (if kbd 'kbd-help 'help-echo))
-        (pair (get-char-property-and-overlay (point) prop))
-        (val (car pair))
-        (ov (cdr pair)))
-    (if (functionp val)
-       (funcall val (selected-window) (if ov ov (current-buffer)) (point))
-      (eval val))))
+  (save-excursion
+    (let* ((prop (if kbd 'kbd-help 'help-echo))
+           (pair (get-char-property-and-overlay (point) prop))
+           (pair (if (car pair) pair
+                     (unless (bobp)
+                       (backward-char)
+                       (get-char-property-and-overlay (point) prop))))
+           (val (car pair))
+           (ov (cdr pair)))
+      (if (functionp val)
+          (funcall val (selected-window) (if ov ov (current-buffer)) (point))
+          (eval val)))))
 
 ;;;###autoload
 (defun help-at-pt-kbd-string ()
   "Return the keyboard help string at point.
 If the `kbd-help' text or overlay property at point produces a
-string, return it.  Otherwise, use the `help-echo' property.  If
-this produces no string either, return nil."
+string, return it.  Otherwise, use the `help-echo' property.
+If this produces no string either, return nil."
   (let ((kbd (help-at-pt-string t))
        (echo (help-at-pt-string)))
     (if (and kbd (not (eq kbd t))) kbd echo)))
@@ -98,8 +101,15 @@ mainly meant for use from Lisp."
        (message "%s" help)
       (if (not arg) (message "No local help at point")))))
 
+(defvar help-at-pt-timer nil
+  "Non-nil means that a timer is set that checks for local help.
+If non-nil, this is the value returned by the call of
+`run-with-idle-timer' that set that timer.  This variable is used
+internally to enable `help-at-pt-display-when-idle'.  Do not set it
+yourself.")
+
 (defcustom help-at-pt-timer-delay 1
-  "*Delay before displaying local help.
+  "Delay before displaying local help.
 This is used if `help-at-pt-display-when-idle' is enabled.
 The value may be an integer or floating point number.
 
@@ -112,17 +122,12 @@ active, but if one is already active, Custom will make it use the
 new value."
   :group 'help-at-pt
   :type 'number
+  :initialize 'custom-initialize-default
   :set (lambda (variable value)
         (set-default variable value)
-        (when (and (boundp 'help-at-pt-timer) help-at-pt-timer)
-          (timer-set-idle-time help-at-pt-timer value t))))
-
-(defvar help-at-pt-timer nil
-  "Non-nil means that a timer is set that checks for local help.
-If non-nil, this is the value returned by the call of
-`run-with-idle-timer' that set that timer.  This variable is used
-internally to enable `help-at-pt-display-when-idle'.  Do not set it
-yourself.")
+        (and (boundp 'help-at-pt-timer)
+             help-at-pt-timer
+             (timer-set-idle-time help-at-pt-timer value t))))
 
 ;;;###autoload
 (defun help-at-pt-cancel-timer ()
@@ -146,7 +151,7 @@ This is done by setting a timer, if none is currently active."
 
 ;;;###autoload
 (defcustom help-at-pt-display-when-idle 'never
-  "*Automatically show local help on point-over.
+  "Automatically show local help on point-over.
 If the value is t, the string obtained from any `kbd-help' or
 `help-echo' property at point is automatically printed in the
 echo area, if nothing else is already displayed there, or after a
@@ -235,7 +240,13 @@ properties, to enable buffer local values."
                (catch 'found
                  (dolist (prop help-at-pt-display-when-idle)
                    (if (get-char-property (point) prop)
-                       (throw 'found t))))))
+                       (throw 'found t)))
+                  (unless (bobp)
+                    (save-excursion
+                      (backward-char)
+                      (dolist (prop help-at-pt-display-when-idle)
+                        (if (get-char-property (point) prop)
+                            (throw 'found t))))))))
        (or (not (current-message))
           (string= (current-message) "Quit"))
        (display-local-help t)))
@@ -244,7 +255,7 @@ properties, to enable buffer local values."
 (defun scan-buf-move-to-region (prop &optional arg hook)
   "Go to the start of the next region with non-nil PROP property.
 Then run HOOK, which should be a quoted symbol that is a normal
-hook.variable, or an expression evaluating to such a symbol.
+hook variable, or an expression evaluating to such a symbol.
 Adjacent areas with different non-nil PROP properties are
 considered different regions.
 
@@ -344,13 +355,10 @@ rarely happens in practice."
 Print the help found there using `display-local-help'.  Adjacent
 areas with different non-nil help-echo properties are considered
 different regions.  With numeric argument ARG, behaves like
-`scan-buf-next-region' with argument -ARG.."
+`scan-buf-next-region' with argument -ARG."
   (interactive "p")
   (scan-buf-move-to-region 'help-echo (- arg) 'scan-buf-move-hook))
 
-(add-hook 'help-at-pt-unload-hook 'help-at-pt-cancel-timer)
-
 (provide 'help-at-pt)
 
-;;; arch-tag: d0b8b86d-d23f-45d0-a82d-208d6205a583
 ;;; help-at-pt.el ends here