0

The built-in backslash fringe bitmap is somewhat mysterious in that it is not available to the user through a common name such as backslash or back-slash. I created my own -- using fringe-helper-convert and define-fringe-bitmap -- but it looks like a miniature staircase instead of a good looking smooth line.

Is there a special name for the built-in backslash fringe bitmap, and if so, what is it called?

The following snippet demonstrates how to display a bitmap in the right fringe (assuming the fringe is visible and wide enough) -- the example uses a question-mark since the built-in backslash appears to be unavailable?

(let ((peol (point-at-eol)))
  (overlay-put (make-overlay peol peol) 'after-string
    (propertize (char-to-string ?\uE000) 'display
      '(right-fringe question-mark font-lock-keyword-face))))

Here are links to the limited documentation regarding fringe bitmaps:

http://www.gnu.org/software/emacs/manual/html_node/elisp/Fringe-Bitmaps.html

http://www.gnu.org/software/emacs/manual/html_node/elisp/Customizing-Bitmaps.html


The built-in fringe backslash is visible in the right fringe in a GUI version of Emacs when the fringes are turned OFF -- i.e., (set-window-fringes (selected-window) 0 0)

Example


Here is my staircase-looking version of the backslash, which is not a smooth line.

;; 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)))

(define-fringe-bitmap 'backslash (fringe-helper-convert
  "XX......"
  "XX......"
  " XX....."
  ".XX....."
  "..XX...."
  "..XX...."
  "...XX..."
  "...XX..."
  "....XX.."
  "....XX.."
  ".....XX."
  ".....XX.") nil nil 'center)
2
  • I only recall seeing such a thing in the terminal version which doesn't have fringes as feature. Can you add a procedure to reproduce a "backslash" fringe?
    – wasamasa
    Commented May 7, 2015 at 21:29
  • @wasamasa -- (set-window-fringes (selected-window) 0 0) causes Emacs to display the backslash in the right fringe when the line wraps at the window edge.
    – lawlist
    Commented May 7, 2015 at 21:41

1 Answer 1

1

When fringes are turned OFF in a GUI version of Emacs, the continuation image that is displayed in what appeared to be the right fringe is actually a glyph, not a bitmap. Therefore, users must create their own backslash if they want to display that image in the fringe -- i.e., the staircase-looking bitmap in the question is about as good as it gets.

See: http://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Tables.html

See also -- the following is the relevant excerpt from xdisp.c:

/* Get information about special display element WHAT in an
   environment described by IT.  WHAT is one of IT_TRUNCATION or
   IT_CONTINUATION.  Maybe produce glyphs for WHAT if IT has a
   non-null glyph_row member.  This function ensures that fields like
   face_id, c, len of IT are left untouched.  */

static void
produce_special_glyphs (struct it *it, enum display_element_type what)
{
  struct it temp_it;
  Lisp_Object gc;
  GLYPH glyph;

  temp_it = *it;
  temp_it.object = make_number (0);
  memset (&temp_it.current, 0, sizeof temp_it.current);

  if (what == IT_CONTINUATION)
    {
      /* Continuation glyph.  For R2L lines, we mirror it by hand.  */
      if (it->bidi_it.paragraph_dir == R2L)
    SET_GLYPH_FROM_CHAR (glyph, '/');
      else
    SET_GLYPH_FROM_CHAR (glyph, '\\');
      if (it->dp
      && (gc = DISP_CONTINUE_GLYPH (it->dp), GLYPH_CODE_P (gc)))
    {
      /* FIXME: Should we mirror GC for R2L lines?  */
      SET_GLYPH_FROM_GLYPH_CODE (glyph, gc);
      spec_glyph_lookup_face (XWINDOW (it->window), &glyph);
    }
    }
  else if (what == IT_TRUNCATION)
    {
      /* Truncation glyph.  */
      SET_GLYPH_FROM_CHAR (glyph, '$');
      if (it->dp
      && (gc = DISP_TRUNC_GLYPH (it->dp), GLYPH_CODE_P (gc)))
    {
      /* FIXME: Should we mirror GC for R2L lines?  */
      SET_GLYPH_FROM_GLYPH_CODE (glyph, gc);
      spec_glyph_lookup_face (XWINDOW (it->window), &glyph);
    }
    }
  else
    emacs_abort ();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.