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

前端 未结 2 1190
自闭症患者
自闭症患者 2021-01-12 13:28

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

2条回答
  •  孤独总比滥情好
    2021-01-12 13:51

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

提交回复
热议问题