Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It Possible To Replace Fringe Bitmaps With Text in Emacs?

Tags:

emacs

fringe

I'd love to replace the ugly pixel arrows indicating truncated or wrapped lines with simple, tasteful text (maybe even a nice unicode character, like a \u2026 ellipsis). Is this possible?

like image 630
Metric Scantlings Avatar asked Apr 19 '13 23:04

Metric Scantlings


2 Answers

No, it is not. Fringe “bitmaps” are really bitmaps, that is vectors of 0/1 bits, overlayed over the fringe. There is no way to directly render arbitrary unicode characters onto the fringe.

What you can do, is to render a unicode character into a 0/1 bitmap yourself. Any decent image editor (e.g. Gimp, Photoshop, Pixelmator, Paint.net, etc.) can do this. Then convert this bitmap into an fringe bitmap vector. The format of fringe bitmaps is described in Customizing Fringe Bitmaps.

Eventually you can use these bitmap vectors to replace the left-arrow, right-arrow (for truncated lines), left-curly-arrow, and right-curly-arrow (for continued lines) bitmaps, using the function define-fringe-bitmap.

However, I'd say that this is more hassle than it is worth. The fringe is 8 pixels wide, so you'd have to squeeze your beautiful unicode character into an 8x8 bitmap. This means no subpixel rendering, no aliasing, no bytecode rendering, nothing of what makes characters on the screen nice and fancy. It'd be just as ugly as the arrows you have replaced.

like image 64
lunaryorn Avatar answered Oct 10 '22 06:10

lunaryorn


The answer by lunaryorn is correct, but it is perhaps beyond the reach of novice Emacs users -- e.g., programmer hobbyists such as myself.

The function fringe-helper-convert written by Nikolaj Schumacher in his library Fringe Helper -- https://github.com/nschum/fringe-helper.el -- makes it easy for Emacs hobbyists like myself to create a vector that is used by the the function define-fringe-bitmap (which is defined in the C-source code of Emacs). I chose a pilcrow, but the user is free to create any image that will fit -- e.g., using the capital letter X and the period ., the user could create the shape of a letter.

;; AUTHOR:  Nikolaj Schumacher -- https://github.com/nschum/fringe-helper.el
(defun fringe-helper-convert (&rest strings)
"Convert STRINGS into a vector usable for `define-fringe-bitmap'.
Each string in STRINGS represents a line of the fringe bitmap.
Periods (.) are background-colored pixel; Xs are foreground-colored. The
fringe bitmap always is aligned to the right. If the fringe has half
width, only the left 4 pixels of an 8 pixel bitmap will be shown.
For example, the following code defines a diagonal line.
\(fringe-helper-convert
\"XX......\"
\"..XX....\"
\"....XX..\"
\"......XX\"\)"
  (unless (cdr strings)
  ;; only one string, probably with newlines
    (setq strings (split-string (car strings) "\n")))
  (apply 'vector
    (mapcar
      (lambda (str)
        (let ((num 0))
          (dolist (c (string-to-list str))
            (setq num (+ (* num 2) (if (eq c ?.) 0 1))))
          num))
      strings)))

The following example assumes a frame-char-height of 20 pixels -- so that the bitmap image is the same height as the text in the buffer. The let-bound snippet creates a pilcrow shape in the right fringe at the end of the line (wherever point is when the snippet is evaluated). The example assumes the right fringe is at least a width of eleven -- e.g., (add-to-list 'default-frame-alist '(right-fringe . 11)) The unicode symbol converted to string -- (char-to-string ?\uE000) could probably be substituted with " ".

(define-fringe-bitmap 'pilcrow (fringe-helper-convert
  "......."
  "......."
  "......."
  "......."
  "......."
  ".XXXXXX"
  "XXXX.X."
  "XXXX.X."
  "XXXX.X."
  ".XXX.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "...X.X."
  "......."
  "......."
  "......."
  "......."))

(let ((peol (point-at-eol)))
  (overlay-put (make-overlay peol peol) 'after-string
    (propertize (char-to-string ?\uE000) 'display
      '(right-fringe pilcrow font-lock-keyword-face))))
like image 31
lawlist Avatar answered Oct 10 '22 05:10

lawlist