emacs-devel
[Top][All Lists]
Advanced

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

Re: More conventient move beginning/end of line


From: Davis Herring
Subject: Re: More conventient move beginning/end of line
Date: Mon, 24 Sep 2007 09:30:08 -0700 (PDT)
User-agent: SquirrelMail/1.4.8-6.el3.2lanl

> Some editor I used long ago had some behaviour similar to the functions
> below. One press on HOME moved to the beginning of line, next to the
> start of the text on that line. It would be nice to have this in Emacs
> (maybe the ARG part should be skipped):

I use these very similar functions.  They use the prefix arg to force the
normal behavior (although I just use C-a and C-e, which I don't rebind,
when I want to avoid these).  They also have "bad" docstrings, of course. 
The important difference is that the end-of-line replacement moves back
before up to one comment and whitespace if repeated.

(defun maybe-beginning-of-line (ARG)
  "Move point to beginning of current line, or to beginning of text
after indentation if already there.  With ARG non-nil, acts as
`move-beginning-of-line'."
  (interactive "P")
  (if (and (bolp) (null ARG)) (back-to-indentation)
    (move-beginning-of-line ARG)))

(defun maybe-end-of-line (ARG)
  "Move point to end of current line, or to end of text before any comment
if already there.  With ARG non-nil, acts as `move-end-of-line'."
  (interactive "P")
  (if (and (eolp) (null ARG))
      (let* ((opoint (point))
             (bpoint (line-beginning-position)))
        ;; `forward-char' is dumb, but not all modes use ?< syntax.
        (while (< (point-after (forward-comment 1)) opoint)
          (skip-syntax-forward " ")
          (forward-char))
        (skip-syntax-backward " " bpoint)
        ;; If there's nothing but a comment, move back to its start.
        (when (bolp) (skip-syntax-forward " " opoint)))
    (move-end-of-line ARG)))

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]