all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Davis Herring" <herring@lanl.gov>
To: "Lennart Borgman (gmail)" <lennart.borgman@gmail.com>
Cc: Emacs Devel <emacs-devel@gnu.org>
Subject: Re: More conventient move beginning/end of line
Date: Mon, 24 Sep 2007 09:30:08 -0700 (PDT)	[thread overview]
Message-ID: <46324.128.165.123.18.1190651408.squirrel@webmail.lanl.gov> (raw)
In-Reply-To: <46F469D2.5070007@gmail.com>

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

      parent reply	other threads:[~2007-09-24 16:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-22  1:03 More conventient move beginning/end of line Lennart Borgman (gmail)
2007-09-22 16:56 ` Thien-Thi Nguyen
2007-09-24 16:30 ` Davis Herring [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46324.128.165.123.18.1190651408.squirrel@webmail.lanl.gov \
    --to=herring@lanl.gov \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.