all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dhruva Krishnamurthy <dhruva.krishnamurthy@gmail.com>
Cc: Lennart Borgman <lennart.borgman.073@student.lu.se>,
	Miles Bader <miles@gnu.org>,
	emacs-devel@gnu.org
Subject: Re: a simple convenience function
Date: Mon, 15 Nov 2004 10:31:29 +0530	[thread overview]
Message-ID: <68c73b1a041114210121be2c58@mail.gmail.com> (raw)
In-Reply-To: <200411150349.57864.pogonyshev@gmx.net>

Hello,


On Mon, 15 Nov 2004 03:49:57 +0200, Paul Pogonyshev <pogonyshev@gmx.net> wrote:
> 
> 
> 
> > Though I found the behaviour suggested by Paul much more mnemonic when
> > bound to the Home key. It is also found in some other editors.
> >
> > - Lennart
> >
> > PS: Maybe I should write it as
> >
> > (defun home-or-back-to-indentation()
> >   (interactive)
> >   (if (bolp) (back-to-indentation) (beginning-of-line)))
> >
> > (define-key global-map [home] 'home-or-back-to-indentation)
> 
> Perhaps, but this way you get it the way round: it will first jump
> to the beginning of line and then to the beginning of the text.
> 

I have a slightly fancy stuff which I use: On first hit on HOME, it
finds whether it is closer to beginning of line or begining of text
and jumps to the closer. Same with end of line. An experienced elisp
geek could clean up significantly... I am learning to walk/crawl in
the elisp ground.

;;-----------------------------------------------------------------------------
;; Intelligent HOME to toggle between 1st text and ZERO column
;;-----------------------------------------------------------------------------
(defun intelli-home()
  "User method to toggle between 1st text and ZERO column"
  (interactive)
  (catch 'ret
    (let ((pos (point)) (blpos (line-beginning-position)) (btpos 0))

      ;; If at begin of line
      (if (= blpos pos)
	  (progn
	    (beginning-of-line-text)
	    (throw 'ret t)))

      (beginning-of-line-text)
      (setq btpos (point))

      ;; If at begin of text
      (if (= btpos pos)
	  (progn
	    (beginning-of-line)
	    (throw 'ret t)))

      ;; Cursor after first text
      (if (> pos btpos)
	  (throw 'ret t))

      ;; Cursor in between begin of line and first text
      ;; Closer to first text
      (if (> (- pos blpos) (- btpos pos))
	  (throw 'ret t))

      ;; Closer to begin line
      (if (or (< (- pos blpos) (- btpos pos))
	      (= (- pos blpos) (- btpos pos)))
	  (progn
	    (beginning-of-line)
	    (throw 'ret t))))))

;;-----------------------------------------------------------------------------
;; Move to end of line text (as beginning-of-line-text)
;;-----------------------------------------------------------------------------
(defun end-of-line-text()
  "User method to simulate beginning-of-line-text for end of line"
  (interactive)
  (end-of-line)
  (while (looking-at "[ \t\n]+")
    (backward-char 1)))

;;-----------------------------------------------------------------------------
;; Intelligent END to toggle between Last text and Last column
;;-----------------------------------------------------------------------------
(defun intelli-end()
  "User method to toggle between Last text and Last column"
  (interactive)
  (catch 'ret
    (let ((pos (point)) (elpos (line-end-position)) (etpos 0))

      ;; If at begin of line
      (if (= elpos pos)
	  (progn
	    (end-of-line-text)
	    (throw 'ret t)))

      (end-of-line)
      (setq etpos (point))

      ;; If at begin of text
      (if (= etpos pos)
	  (progn
	    (end-of-line)
	    (throw 'ret t)))

      ;; Cursor after first text
      (if (< pos etpos)
	  (throw 'ret t))

      ;; Cursor in between begin of line and first text
      ;; Closer to first text
      (if (< (- pos elpos) (- etpos pos))
	  (throw 'ret t))

      ;; Closer to begin line
      (if (or (> (- pos elpos) (- etpos pos))
	      (= (- pos elpos) (- etpos pos)))
	  (progn
	    (end-of-line)
	    (throw 'ret t))))))

;; Key bindings
(global-set-key [end]  'intelli-end)
(global-set-key [home] 'intelli-home)

- dhruva
-- 
Proud FSF member: #1935
http://schemer.fateback.com/

  reply	other threads:[~2004-11-15  5:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-14 21:36 a simple convenience function Paul Pogonyshev
2004-11-14 23:34 ` Miles Bader
2004-11-15  0:22   ` Lennart Borgman
2004-11-15  1:49     ` Paul Pogonyshev
2004-11-15  5:01       ` Dhruva Krishnamurthy [this message]
2004-11-15  7:28       ` Lennart Borgman
2004-11-15  1:50   ` Paul Pogonyshev
2004-11-15  6:45 ` Thien-Thi Nguyen
2004-11-15  9:29 ` Kai Grossjohann
2004-11-15 23:14   ` Alex Schroeder
2004-11-15 23:27     ` Lennart Borgman
2004-11-16 17:11     ` Kai Grossjohann
2004-11-16 17:14     ` Kai Grossjohann
2004-11-16 17:20     ` Kai Grossjohann

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=68c73b1a041114210121be2c58@mail.gmail.com \
    --to=dhruva.krishnamurthy@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman.073@student.lu.se \
    --cc=miles@gnu.org \
    /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.