all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* More conventient move beginning/end of line
@ 2007-09-22  1:03 Lennart Borgman (gmail)
  2007-09-22 16:56 ` Thien-Thi Nguyen
  2007-09-24 16:30 ` Davis Herring
  0 siblings, 2 replies; 3+ messages in thread
From: Lennart Borgman (gmail) @ 2007-09-22  1:03 UTC (permalink / raw)
  To: Emacs Devel

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):

(defun my-move-beginning-of-line(arg)
   (interactive "p")
   (or arg (setq arg 1))
   (let ((pos (point)))
     (move-beginning-of-line arg)
     (when (= pos (point)) (skip-chars-forward " \t"))))
(put 'my-move-beginning-of-line 'CUA 'move)
(global-set-key [home] 'my-move-beginning-of-line)

(defun my-move-end-of-line(arg)
   (interactive "p")
   (or arg (setq arg 1))
   (let ((pos (point)))
     (move-end-of-line arg)
     (when (= pos (point)) (skip-chars-backward " \t"))))
(put 'my-move-end-of-line 'CUA 'move)
(global-set-key [end] 'my-move-end-of-line)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: More conventient move beginning/end of line
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Thien-Thi Nguyen @ 2007-09-22 16:56 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

() "Lennart Borgman (gmail)" <lennart.borgman@gmail.com>
() Sat, 22 Sep 2007 03:03:14 +0200

   (defun my-move-beginning-of-line(arg) ...)
   (defun my-move-end-of-line(arg) ...)

see also codeline.el, reachable via
<http://www.gnuvola.org/software/personal-elisp/index.html>

thi

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: More conventient move beginning/end of line
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Davis Herring @ 2007-09-24 16:30 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-09-24 16:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.