antonj / Highlight-Indentation-for-Emacs

Minor modes to highlight indentation guides in emacs.
467 stars 56 forks source link

Is it possible to use dot instead of face for indentation guides ? #16

Open lxsameer opened 10 years ago

lxsameer commented 10 years ago

Is it possible to use dot instead of face for indentation guides ? or a character like middle dot ? for example something like this:

class Sample
.    def method1
.    .    puts "hey"
.    end
ahmadseleem commented 10 years ago

If possible I am in :)

letronje commented 10 years ago

+1

vlcek commented 10 years ago

Hi, here is a quick way how to do that. I've created a X bitmap image and used it as a value for stipple face attribute.

define vline_width 7

define vline_height 4

static unsigned char vline_bits[] = { 0x10, 0x00, 0x00, 0x00 };

There are some problems with pixel width of chars (you have to have same pixel width of xbm image and character or it gets messy). In my case it's 7 pixels. You can check yours with

(frame-char-width (selected-frame))

and adjust the image accordingly.

Here is some elisp for adjusting faces

(set-face-attribute 'highlight-indentation-face nil
                     :stipple (list 7 4 (string 16 0 0 0))
                     :inherit nil)

 (set-face-attribute 'highlight-indentation-current-column-face nil
                     :stipple (list 7 4 (string 16 0 0 0))
                     :inherit nil
                     :foreground "yellow")))

and here is a preview.

highlight-indentation

kepi commented 10 years ago

looks amazing @vlcek thanks

bassu commented 10 years ago

@vlcek can you please create a patch?

stardiviner commented 10 years ago

+1

Lenbok commented 10 years ago

I would be very happy if you could specify both a mark character and a face (kind of like how whitespace-mode does it). Then you could e.g. have a faint '|' character. No worrying about pixel widths since it's a regular character.

xuhdev commented 9 years ago

Fill-Column-Indicator is able to draw a dashed line. Maybe something can be borrowed from there?

ReneFroger commented 9 years ago

Awesome work, @vlcek !

However, I couldn't figure out how I could create a bitmap image in Paint, with the settings that you deliverd.

#define vline_width 8
#define vline_height 4
static unsigned char vline_bits[] = { 
 0x10, 0x00, 0x00, 0x00 };

Any suggestion?

stardiviner commented 9 years ago

indent-guide can specify indent line symbol. you can use similar unicode symbols to archive this effect.

Lenbok commented 9 years ago

@ReneFroger This is what I use in my .emacs which seems to work pretty well for a decent range of font widths (up to char width of 16 pixels). It sets the stipple when enabling highlight-indentation mode on a buffer and looks at the current frame parameters to work out which stipple to set. It can probably be improved to handle an even wider range of widths.

(require 'highlight-indentation)
(defun my-set-highlight-stipple ()
  ;; Define custom stipple for highlight-indentation
  ;; See https://github.com/antonj/Highlight-Indentation-for-Emacs/issues/16
  (let* ((char-width (frame-char-width (selected-frame)))
        (hl-stipple (if (> char-width 8)
                        (list char-width 4 (string 16 0 0 0 0 0 0 0))
                      (list char-width 4 (string 16 0 0 0)))))
    (set-face-attribute 'highlight-indentation-face nil
                        :stipple hl-stipple
                        :inherit nil)
    (set-face-attribute 'highlight-indentation-current-column-face nil
                        :stipple hl-stipple
                        :inherit nil
                        :foreground "yellow"))
  )
;; Patch highlight-indentation-mode to set/update a stipple attribute
(defadvice highlight-indentation-mode (before set-highlight-indentation-stipple activate)
"Sets the stipple used by indentation highlighting"
  (my-set-highlight-stipple))

(edit: included char-width directly in the stipple list).

ReneFroger commented 9 years ago

Sorry for my belated response, thanks for your reply, I really appreciate it.

I tried your setup, with char-width 7 and char-width 8 without any result. I use Consolas as font by the way, the setting for the font is configured as (set-face-attribute 'default nil :height 110 :family "Consolas").

Any suggestion in order to debug this?

Thanks in advance.

ReneFroger commented 9 years ago

@Lenbok any chance that your setup is working with Consolas?

Lenbok commented 9 years ago

@ReneFroger Yep, I just installed consolas (nice font!) and:

consolas-indentation

sangm commented 9 years ago

This is what I get, any ideas? @Lenbok

image

geraldus commented 9 years ago

Hey folks, is it possible to use a unicode glyph rather than bitmap, for example , , , ? I haven't got used with overlays (yet).

bassu commented 9 years ago

@geraldus Probably not. But see indent-guide mode. It also works with tabs.

geraldus commented 9 years ago

@bassu you've made my day! Many thanks!

zhro commented 9 years ago

I would also like to see the ability to use a Unicode glyph as I typically run emacs in terminal mode.

tam5 commented 6 years ago

@Lenbok your snippet looks promising, but when i paste it into my .emacs it doesn't seem to have any affect.

Does this still work (Emacs version 27.0.50)

berendo commented 5 years ago

Does this still work (Emacs version 27.0.50)

It looks like the :stipple face attribute support in Emacs really only works with X11 windowing based builds, not terminal or macOS versions (given it relies on X11 bitmap support).

ColemanGariety commented 4 years ago

It would be super nice if we could use glyphs for terminal emacs :)

bfonta commented 2 years ago

By slightly modifying the above snippet one can get thin vertical guide lines:

Screenshot from 2022-05-04 14-01-24

(set-face-attribute 'highlight-indentation-face nil
                    :stipple (list (frame-char-width (selected-frame)) 4 (string 16 16 16 16))
                    :inherit nil
            :foreground "peru")

Information on how :stipple works can be found here.