--- tooltip.el 2020-08-21 15:12:24.108484748 +0200 +++ lisp/tooltip.el 2020-10-05 02:47:13.662826815 +0200 @@ -26,6 +26,7 @@ ;;; Code: (require 'syntax) +(require 'widget) ; for "sticky" tooltips (defvar comint-prompt-regexp) @@ -164,6 +165,14 @@ :group 'tooltip :version "27.1") +(defcustom tooltip-enable-sticky nil + "Set this variable to true to enable `sticky' tooltip interface. +This variable does not have effect when Gtk tooltips are enabled + (requires Emacs to be compiled with Gtk suppoart and + x-gtk-use-system-tootlip to be set to true)." + :type 'boolean + :group 'tooltip) + ;;; Variables that are not customizable. @@ -258,12 +267,61 @@ (setf (alist-get 'border-color params) fg)) (when (stringp bg) (setf (alist-get 'background-color params) bg)) - (x-show-tip (propertize text 'face 'tooltip) - (selected-frame) - params - tooltip-hide-delay - tooltip-x-offset - tooltip-y-offset)) + (if x-gtk-use-system-tooltips + (x-show-tip (propertize text 'face 'tooltip) + (selected-frame) + params + tooltip-hide-delay + tooltip-x-offset + tooltip-y-offset) + + ;; we are not using gtk + (with-current-buffer (get-buffer-create " *tip*") + (let ((inhibit-read-only t)) + (erase-buffer) + (remove-overlays) + (insert (propertize text 'face 'tooltip)) + + (when tooltip-enable-sticky + (goto-char (point-min)) + (let ((cur-line 0) + (lng-line 0)) + (while (not (eobp)) + (setq cur-line (- (line-end-position) (line-beginning-position))) + (when (> cur-line lng-line) + (setq lng-line cur-line)) + (forward-line)) + + (newline) + + ;; (insert (propertize + ;; (make-string (- lng-line 6) ?─) + ;; 'face 'tooltip)) + ;; (widget-insert (propertize " Sticky " 'face + ;; 'tooltip)) + (insert (make-string (- lng-line 6) ?─)) + (widget-insert " Sticky ") + (widget-create 'checkbox + :notify (lambda (s &rest ignore) + (if (widget-value s) + (progn ;; OBS nothing here yet + ;; (when tooltip-timer + ;; (cancel-timer tooltip-timer) + ;; (setq tooltip-timer nil)) + ) + ;; else + (tooltip-hide)))) + (use-local-map widget-keymap) + (widget-setup))) + + ;; this (propertize text ... ) here is unnecessary + ;; ... but this is just a fast hack + (x-show-tip (propertize text 'face 'tooltip) + (selected-frame) + params + tooltip-hide-delay + tooltip-x-offset + tooltip-y-offset))))) (error (message "Error while displaying tooltip: %s" error) (sit-for 1)