[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reducing mouse-dependency In Emacs.

From: Luc Teirlinck
Subject: Re: Reducing mouse-dependency In Emacs.
Date: Mon, 11 Aug 2003 20:29:58 -0500 (CDT)

Here are my highlighting functions for text-properties.

You can do C-h C-k to highlight help-echo regions and C-u C-h C-k to
remove the highlight.  To make things more interesting, you should
have adjacent regions with different non-nil help-echo properties.

More generally, M-x highlight-text-property-regions will prompt for a
property and two faces.  Specifying nil for the first face will remove
any highlight associated with the property.

These functions are more meant to get an idea of "what is in the
buffer" than for permanent highlighting.  They do _not_ automatically
set a timer to update.

===File ~/highlightprops.el=================================
(defun highlight-text-property-regions (prop &optional face1 face2)
  "Highlight regions with non-nil text or overlay property PROP.
Regions get highlighted using face1, except that adjacent regions
with non-nil but different PROP properties get highlighted
alternatively with face1 and face2.
If face1 is nil, remove all highlighting.
If face2 is nil, highlight all regions with face1."
  (interactive "SProperty to highlight: \nSMain face: \nSBackup face: ")
  (unless prop (error "PROP must be non-nil"))
  (let ((overlay-list (overlays-in (point-min) (point-max))))
    (dolist (overlay overlay-list)
      (when (eq (overlay-get overlay 'highlight-text-property-regions) prop)
        (delete-overlay overlay))))
  (if face1
      (let ((pos (point-min))
            (current-face face1)
            (change-face nil)
        (overlay-recenter (point-max))
        (unless face2 (setq face2 face1))
        (while (/= pos (point-max))
          (if (get-char-property pos prop)
                (setq oldpos pos)
                (setq pos (next-single-char-property-change pos prop))
                (if change-face
                    (setq current-face (if (eq current-face face1)
                                           face2 face1)))
                (setq current-overlay
                      (make-overlay oldpos pos (current-buffer) t)) 
                (overlay-put current-overlay 'face current-face)
                (overlay-put current-overlay
                             'highlight-text-property-regions prop)
                (setq change-face t))
            (setq pos (next-single-char-property-change pos prop))
            (setq change-face nil))))))

(defface help-echo-primary-face
  '((t (:background "yellow")))
  "Used by `highlight-help-echo-regions' as its main face."
  :group 'faces)

(defface help-echo-secondary-face
  '((t (:background "orange")))
  "Used by `highlight-help-echo-regions' as its secondary face."
  :group 'faces)

(defun highlight-help-echo-regions (&optional arg)
  "Highlight regions with non-nil help-echo-property.
With a numeric argumenr, remove all such highlighting.
Regions are normally highlighted with `help-echo-primary-face'.
However, regions are highlighted with'help-echo-secondary-face',
if necessary to distinguish them from adjacent regions.  This is
mainly useful for temporary highlighting, as it might override
other highlighting. No automatic updating takes place."
  (interactive "P")
  (if arg (highlight-text-property-regions 'help-echo)
     'help-echo 'help-echo-primary-face 'help-echo-secondary-face)))

(global-set-key "\C-h\C-k" 'highlight-help-echo-regions)        

reply via email to

[Prev in Thread] Current Thread [Next in Thread]