[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ASCII formatting for plain text email



Hi,

<tomas@tuxteam.de> wrote:

> I don't know currently the Emacs incantation to right-justify a line

Mabye there already exists something for this but it's easy enough to
code:

;;; **************************************************************************
;;; *                     Right-justification of a line                      *
;;; **************************************************************************
(defun my-right-justify-current-line (columns)
  "Right-justify the current line within the given numbers of columns.

If COLUMNS is nil (which is the case in interactive mode when no
prefix is given), use the value of `fill-column'."
  (interactive "p")
  (save-excursion
    (beginning-of-line)
    (just-one-space 0)  ; remove spaces at the beginning of the line
    (let ((len
           (-
            (progn (end-of-line) (just-one-space 0) (point))
            (progn (beginning-of-line) (point))
            )
           )
          (ncols (cond ((null current-prefix-arg) fill-column)
                       ((eq '- current-prefix-arg)
                        (error "COLUMNS should be either nil or an integer"))
                       (t (prefix-numeric-value current-prefix-arg)))))
      (if (> len ncols)
          (error "COLUMNS is too small to hold text on the current line"))
      (beginning-of-line)
      (insert (make-string (- ncols len) ? ))
      )))

;; Whatever shortcut you want
(global-set-key [C-f11] 'my-right-justify-current-line)

Then you can do “C-f11” to right-justify within `fill-column' columns;
prefix this with, e.g., “C-u 7 2” in order to right-justify within 72
columns without touching to the `fill-column' variable.

If you like how the “Right-justification of a line” comment is
presented, I have a function for this too (written about 20 years ago
when I was learning and practicing ELisp!).

HTH, regards

-- 
Florent


Reply to: