1 ;;; fuel-autohelp.el -- help pages in another window -*- lexical-binding: t -*-
3 ;; Copyright (C) 2013 Erik Charlebois
4 ;; See http://factorcode.org/license.txt for BSD license.
6 ;; Author: Erik Charlebois <erikcharlebois@gmail.com>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Mon Mar 25, 2012, 11:46
12 ;; Utilities for displaying help in a side window.
18 (require 'factor-mode)
24 (defgroup fuel-autohelp nil
25 "Options controlling FUEL's autohelp system."
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.
33 If this variable is set to 0, no idle time is required."
35 :group 'fuel-autohelp)
39 (defvar fuel-autohelp-timer nil "Autohelp's timer object.")
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
46 (defun fuel-autohelp-show-current-symbol-help ()
48 (when (and (boundp 'fuel-autohelp-mode) fuel-autohelp-mode)
49 (let ((word (factor-symbol-at-point))
50 (fuel-log--inhibit-p t))
52 (fuel-help--word-help word t))))
53 (error (message "FUEL Autohelp error: %s" err))))
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)))
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))))
70 (defvar-local fuel-autohelp-mode-string " H"
71 "Modeline indicator for fuel-autohelp-mode")
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.
80 When Autohelp mode is enabled, the help for the word is displayed
83 :lighter fuel-autohelp-mode-string
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)))
91 (defun turn-on-fuel-autohelp-mode ()
92 "Unequivocally turn on FUEL's Autohelp mode (see command
93 `fuel-autohelp-mode')."
95 (fuel-autohelp-mode 1))
98 (provide 'fuel-autohelp)
100 ;;; fuel-autohelp.el ends here