]> gitweb.factorcode.org Git - factor.git/blob - misc/fuel/fuel-autohelp.el
Use lexical scoping in all fuel sources
[factor.git] / misc / fuel / fuel-autohelp.el
1 ;;; fuel-autohelp.el -- help pages in another window -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2013 Erik Charlebois
4 ;; See http://factorcode.org/license.txt for BSD license.
5
6 ;; Author: Erik Charlebois <erikcharlebois@gmail.com>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Mon Mar 25, 2012, 11:46
9
10 ;;; Commentary:
11
12 ;; Utilities for displaying help in a side window.
13
14 ;;; Code:
15
16 (require 'fuel-base)
17 (require 'fuel-help)
18 (require 'factor-mode)
19
20 \f
21 ;;; Customization:
22
23 ;;;###autoload
24 (defgroup fuel-autohelp nil
25   "Options controlling FUEL's autohelp system."
26   :group 'fuel)
27
28 (defcustom fuel-autohelp-idle-delay 0.7
29   "Number of seconds of idle time to wait before printing.
30 If user input arrives before this interval of time has elapsed after the
31 last input, no documentation will be printed.
32
33 If this variable is set to 0, no idle time is required."
34   :type 'number
35   :group 'fuel-autohelp)
36
37 \f
38 ;;; Helper function:
39 (defvar fuel-autohelp-timer nil "Autohelp's timer object.")
40
41 (defvar fuel-autohelp-current-idle-delay fuel-autohelp-idle-delay
42   "Idle time delay currently in use by timer.
43 This is used to determine if `fuel-autohelp-idle-delay' is changed by the
44 user.")
45
46 (defun fuel-autohelp-show-current-symbol-help ()
47   (condition-case err
48       (when (and (boundp 'fuel-autohelp-mode) fuel-autohelp-mode)
49         (let ((word (factor-symbol-at-point))
50               (fuel-log--inhibit-p t))
51           (when word
52             (fuel-help--word-help word t))))
53     (error (message "FUEL Autohelp error: %s" err))))
54
55 (defun fuel-autohelp-schedule-timer ()
56   (or (and fuel-autohelp-timer
57            (memq fuel-autohelp-timer timer-idle-list))
58       (setq fuel-autohelp-timer
59             (run-with-idle-timer fuel-autohelp-idle-delay t
60                                  'fuel-autohelp-show-current-symbol-help)))
61
62   ;; If user has changed the idle delay, update the timer.
63   (cond ((not (= fuel-autohelp-idle-delay fuel-autohelp-current-idle-delay))
64          (setq fuel-autohelp-current-idle-delay fuel-autohelp-idle-delay)
65          (timer-set-idle-time fuel-autohelp-timer fuel-autohelp-idle-delay t))))
66
67 \f
68 ;;; Autohelp mode:
69
70 (defvar-local fuel-autohelp-mode-string " H"
71   "Modeline indicator for fuel-autohelp-mode")
72
73 ;;;###autoload
74 (define-minor-mode fuel-autohelp-mode
75   "Toggle Fuel's Autohelp mode.
76 With no argument, this command toggles the mode.
77 Non-null prefix argument turns on the mode.
78 Null prefix argument turns off the mode.
79
80 When Autohelp mode is enabled, the help for the word is displayed
81 in another window."
82   :init-value nil
83   :lighter fuel-autohelp-mode-string
84   :group 'fuel-autohelp
85
86   (if fuel-autohelp-mode
87       (add-hook 'post-command-hook 'fuel-autohelp-schedule-timer nil t)
88     (remove-hook 'post-command-hook 'fuel-autohelp-schedule-timer)))
89
90 ;;;###autoload
91 (defun turn-on-fuel-autohelp-mode ()
92   "Unequivocally turn on FUEL's Autohelp mode (see command
93 `fuel-autohelp-mode')."
94   (interactive)
95   (fuel-autohelp-mode 1))
96
97 \f
98 (provide 'fuel-autohelp)
99
100 ;;; fuel-autohelp.el ends here