MarginMode

From the homepage:

One nice feature in modern IDEs is the display of a faint one-pixel wide righthand margin that offers a visual clue to the length of each source code line. […] You can achieve similar functionality in Emacs by marking lines which exceed a specified length (usually 80 characters) […]

This could use a bit more explanation:

  (defun margin-change (beg end)
    "Refresh margins in region BEG to END."
    (save-excursion 
      (dolist (o (overlays-in beg end))
        (when (margin-overlay-p o)
          (delete-overlay o)))
      
      (goto-char beg)
      (while (> end (point))
        (let ((start-of-line (line-beginning-position))
              (end-of-line (line-end-position)))
          (make-margin-overlay start-of-line end-of-line)
          (goto-char (+ end-of-line 1))))))

Also consider vvb-mode (Visible Vertical Bar): Geocities:gchen275/xemacs/

Visualized Fill-column margin in GNU Emacs?

I am looking for a minor mode for emacs which shows the area right of the fill column in another color, regardless if any characters have been typed into that area or not. Think of a window which is split into two parts which differ by the background color: left a white part and right a light gray part which is beyond the fill column. Anyone? I’ve not been successfuly googling about that.

Thanks, Lennart

There is vvb-mode.el — a minor mode to display a Visible Vertical Bar(s). There is a XEmacs version on the EmacsLispList. a Variant for GNU Emacs was posted on gnu.emacs.sources on 2003-01-16
Thank you for this tip. Unfortunately this script (I used the GNU Emacs 21 version available from http://gnufans.net/~deego/emacspub/site-lisp-not/vvb-mode.el.gz) doesn’t work very well and doesn’t show any bars when a line is shorter than the bar column. ;-(. It seems as if such a script is not possible to be implemented with current emacs.
Thanks, Lennart

Both (thin line and highlighting) is possible with overlays. Here is a, horrible slow, proof of concept:

(defvar highlight-fill-column-string "\u2502")
(defvar highlight-fill-column-face 'highlight)

(defun highlight-fill-column (&rest _)
  (remove-overlays nil nil 'highlight-fill-column t)
  (save-excursion
    (goto-char (point-min))
    (while (not (eobp))
      (let ((rest-width (- fill-column
                           (save-excursion
                             (end-of-line)
                             (current-column)))))
        (let* ((ov (make-overlay
                    (line-end-position) (1+ (line-end-position)) nil t))
               (ov2 (copy-overlay ov))
               (string (concat
                        (when (> rest-width 0)
                          (propertize (string 32)
                                      'display `(space-width ,rest-width)
                                      'cursor t))
                        (when (>= rest-width 0)
                          (propertize highlight-fill-column-string
                                      'cursor (= rest-width 0))))))
          (overlay-put ov 'before-string string)
          (overlay-put ov2 'face highlight-fill-column-face)
          (overlay-put ov 'priority 1)
          (overlay-put ov2 'priority 2)
          (overlay-put ov 'highlight-fill-column t)
          (overlay-put ov2 'highlight-fill-column t)))
      (next-line))))

(define-minor-mode highlight-fill-column-mode
  nil nil nil nil nil
  (if highlight-fill-column-mode
      (progn
        (add-hook 'after-change-functions 'highlight-fill-column nil t)
        (highlight-fill-column))
    (remove-overlays nil nil 'highlight-fill-column t)
    (remove-hook 'after-change-functions 'highlight-fill-column  t)))

Font-lock suggestion

I (and, it seems, many others) would like to be able to specify a right edge column and then have a single pixel wide line drawn at that column. Such a feature has existed in many much simpler editors going back more than 10 years. I have a colleague who uses CodeWright and that vertical bar is the only feature I covet. – JohnYates

You can do this using font-lock mode. Add a pattern that matches column N and then assign a face that has a pixmap with a single pixel vertical line. – AmitPatel

That sort of thing only works for lines which have text at that column, though I’m not sure why anything else is necessary.

What I am using is highlight-beyond-fill-column. It only works for a specific fill-column though.

Lisp:column-marker.el does exactly what you’re asking for.

Can someone please demonstrate how? As stated above, column-marker.el only marks the column if there is text there, and it highlights the whole column rather than displaying a single, one-pixel-wide line, so I’m pretty sure that column-marker’s default configuration is not what JohnYates was asking for.

What do you need to do to make it look more like the Visual Studio guidelines feature – for instance, http://blogs.msdn.com/b/saraford/archive/2004/11/15/257953.aspx ? I didn’t get anywhere customizing the column-marker-1 face.

FillColumnIndicator can display that sort of one-pixel line.


See also: ColumnMarker, EightyColumnRule, FillColumnIndicator, and HighlightLongLines.

CategoryFilling CategoryModes CategoryDisplay CategoryEditing