Giter Site home page Giter Site logo

highlight-thing.el's Introduction

highlight-thing.el

Global minor mode to highlight the thing under point.

MELPA

Similar to highlight-symbol-mode, but does not rely on font-lock functionality and does not provide functionality to navigate to different occurrences of the current symbol under point.

No external dependencies, uses thingatpt and hi-lock functionality that is included with GNU Emacs.

Demo

Installation

Basic setup:

  (require 'highlight-thing)
  (global-highlight-thing-mode)

Alternatively you can use the buffer-local version:

  (add-hook 'prog-mode-hook 'highlight-thing-mode)

The default is to highlight the symbol under point, but you can customize hightlight-thing-what-thing to highlight different components. Set the following to only highlight the word under point:

  (setq highlight-thing-what-thing 'word)

As an extension to the thing-at-point capabilities you can select region in which case an active region is used as the thing to highlight (cf. #7).

@antoineB provided the functionality to use a custom regex function for a thing-at-point - thanks! For his use case, cf. #18. To use it store the custom regex function as the property highlight-thing-regex-fn on your thing-at-point:

  (put 'word 'highlight-thing-regex-fn 'your-regex-fn)

Customize the face hi-yellow to change the colors that are used for highlighting.

You can customize the delay before this mode attempts to highlight the thing under point. For example, push it out to 1.5 seconds from the default 0.5:

  (setq highlight-thing-delay-seconds 1.5)

You can limit the highlighting of things to the current defun via the following setting:

  (setq highlight-thing-limit-to-defun t)

You can configure the matching of occurrences to be case-sensitive via the following setting:

  (setq highlight-thing-case-sensitive-p t)

If you want all the matches highlighted but not the one occurrence at the point itself, you can do so by:

  ;; Don't highlight the thing at point itself. Default is nil.
  (setq highlight-thing-exclude-thing-under-point t)

If you want to highlight the current region when active or thing at point when inactive:

  (setq highlight-thing-prefer-active-region t)

If you want to prevent highlighting certain strings:

  (setq highlight-thing-ignore-list '("False" "True"))

If you want to highlight in all visible buffers:

  (setq highlight-thing-all-visible-buffers-p t)

If you want to restrict the highlighting to lines surrounding points, e.g. to reduce the load of highlighting in large buffers as in #16, consider customizing the following variables:

  (setq highlight-thing-limit-to-region-in-large-buffers-p nil
        highlight-thing-narrow-region-lines 15
        highlight-thing-large-buffer-limit 5000)

highlight-thing.el's People

Contributors

antoineb avatar fgeller avatar fuco1 avatar kaligule avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

highlight-thing.el's Issues

Feature request: highlight text like region only

It would be nice to have things highlighted only if they are selected in the region.

This would mean your eye isn't distracted when doing simple typing, but only when selecting stuff like variables and lines that repeat frewuently. It could also lead to nice synergy effects with other packages like expand-region etc for free.

README outdated

Not really sure, but it seems that highlight-symbol.el requires thingatpt only to work properly.

error when disable highlight-thing-mode

when i disable, i get an error:
Highlight-Thing mode disabled
Error running timer `highlight-thing-loop': (void-function highlight-thing-remove-last-highlight) [12 times]

it works if i change the definitions of highlight-thing-deactivate to turn highlight-thing-remove-last-highlight into highlight-thing-remove-last:

(defun highlight-thing-deactivate ()
(highlight-thing-remove-last))
(when highlight-thing-timer (cancel-timer highlight-thing-timer))

(defun highlight-thing-deactivate ()
(highlight-thing-remove-last)
(when highlight-thing-timer (cancel-timer highlight-thing-timer)))

cheers
jack

Freeze on big buffers

Hi, thanks for this. It's working good, but I encountered a problem with big buffers.

I opened a 110kb csv with global-highlight-thing-mode on and my emacs just stopped working (not responding even to C-g).

Is it possible to limit the search to visible part, or to cursor +/- X lines? Else a timeout that tells it might not take more than X seconds or something.

Thanks, Nicolò

Emacs freezes when highlighting an empty region

Hi! Thanks for the package, but I think I found a bug that freezes Emacs (tested on Emacs 28.1 Windows 11).

When setting the highlight mode to region:

(setq highlight-thing-what-thing 'region)

If i set the mark with C-SPC and then wait for highlight-thing-delay-seconds seconds (by default 0.5s), the CPU spikes to 100%, memory usage keeps growing and Emacs becomes unresponsive (can't use C-g or ESC, only way to exit is killing the process).

I think this happens when (point) and (mark) are equal, the highlight-thing-get-active-region function returns the empty string and this is passed to the highlight-thing-get-thing-at-point function. I fixed this bug by replacing thing with (if (string= "" thing) nil thing) at the last expression of the highlight-thing-get-thing-at-point function:

(defun highlight-thing-get-thing-at-point ()
  (let ((thing (if (highlight-thing-should-highlight-region-p) (highlight-thing-get-active-region)
                 (thing-at-point highlight-thing-what-thing))))
    (unless (member thing highlight-thing-ignore-list)
     (if (string= "" thing) nil thing)))) ;; <---

But I'm not sure if this is the proper place to fix this issue.

Thanks.

Failed to change highlight-thing face

First of all, thanks for making this package -- I really love it!
However, when I tried to change the highlight face with (set-face-attribute 'highlight-thing nil :foreground "white"), Emacs tellls me Invalid face: highlight-thing. How should I approach this?

Feature request: highlight only occurences in current defun

thingatpt has a defun method so you can test if point is inside a defun or not. If so, narrow before applying the highlight (at least, I hope hi-lock can use that).

What do you think? Often the symbol has no relevance outside the defun. Of course, you can make this an opt-in feature.

Point moves in ruby when over the `module` keyword

This is really odd and I can't explain it, here is what I do:

  1. make a clean buffer

  2. input

    module

    end

  3. place point over m in module

  4. point should spotaneously move forward one character.

I guess there's a missing save-excursion somewhere, unfortunately I don't have time to look into it.

Ignore list

Hi,

I've being using highlight-symbol and I found this one today and I liked it more because it has some configurations that the other one doesn't have.

The only thing that this one is missing, I think, it's the ability to add symbols to an ignore list and don't highlight them. I found this very useful because otherwise I feel like it's too intrusive.

For example, my list it's similar to this (for Python code):

(setq highlight-symbol-ignore-list
      '("False" "True" "None" "self" "def" "import" "from" "if" "else" "for" "while" "class" "print" "and" "not" "is" "param" "type" "rtype" "async"))

That's all, thank you for this code! :)

Option to highlight only after only double click

By default all occurrences of the thing under the cursor get highlighted. This can be distracting while typing, especially since the default highlight color is almost the same as the cursor.
Is it possible to add an option so that only things selected with a double click get highlighted (similar to what sublime text does)?

Controlling case sensitivity

I would like highlight-thing to be case-sensitive when in a coding mode.

Here's an example of why it's useful:

case-insensitive

Because it's not currently case-sensitive, I don't notice that the variable I'm defining (allowlist) doesn't match the usage below (allowList).

Feature request: exclude matches in comment blocks

It would be useful for me if it were possible configure highlight-thing-mode to prevent an instance of a symbol from being highlighted if that instance is part of a comment block or code intended for documentation (e.g. if the face is font-lock-comment-face or font-lock-doc-face).

Thanks for the great work on this minor mode!

Selecting a part of a symbol highlights the rest of the symbol.

Here's how it looks when I select thing in highlight-thing-case-sensitive-p:

Screenshot from 2022-04-04 16-30-49

I don't remember than happening before. I think it started to work this way either after I switched to using the dark mode (unlikely) or after I upgraded to a newer emacs version (most likely).

Config:

(use-package highlight-thing
  :ensure t
  :diminish)
(global-highlight-thing-mode)
(setq highlight-thing-case-sensitive-p t)
(setq highlight-thing-delay-seconds 0)
(setq highlight-thing-exclude-thing-under-point t)

Emacs version: 26.3.

How do I change the highlight color?

I look at the commit, but could not figure it out..
This is what I got:

(use-package 
  highlight-thing 
  :ensure t 
  :config (global-highlight-thing-mode))
(defface highlight-thing
   '((t (:inherit 'hi-black-hb))) "")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.