is there left,right equivalents in evil or native emacs?

Wolfgang Jenkner wjenkner at inode.at
Thu Dec 22 06:28:08 CET 2011


Frank Fischer <frank.fischer at mathematik.tu-chemnitz.de> writes:

> On Sat, Dec 17, 2011 at 06:32:03AM +0000, Jim Green wrote:
>> Hi, Frank and list:
>> 
>> in evil or emacs how to achive the following two commands?
>> :[range]ri[ght] [width]                                 :ri :right
>>                                                         :le :left
>> :[range]le[ft] [indent]
>
> But, of course, if there is some function doing this,
> it's not a real problem to bind them in ex-mode.

Just for the record...

#+begin_src emacs-lisp

(evil-define-operator evil-align-right (beg end type &optional width)
  "Right-align lines in the region at WIDTH columns.
The default for width is the value of `fill-column'."
  :motion evil-line
  :type line
  (interactive "<R><a>")
  (let ((fill-column (if width
			 (string-to-number width)
		       fill-column))
	adaptive-fill-mode fill-prefix)
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (while (progn
	       (justify-current-line 'right nil t)
	       (zerop (forward-line)))))))

(evil-ex-define-cmd "right" 'evil-align-right)

#+end_src

The following snippet would work as well, but it would also canonicalize
whitespace.

#+begin_src emacs-lisp

(evil-define-operator evil-align-right (beg end type &optional width)
  ...
  (let ((paragraph-start "")
	(paragraph-separate "$")
	...)
    (fill-individual-paragraphs beg end 'right)))

#+end_src


Wolfgang



More information about the implementations-list mailing list