all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* a simple convenience function
@ 2004-11-14 21:36 Paul Pogonyshev
  2004-11-14 23:34 ` Miles Bader
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Paul Pogonyshev @ 2004-11-14 21:36 UTC (permalink / raw)


I'm not sure this issue wasn't raised already, but what do
you think about adding this simple function to Emasc?  It
could just sit there for optional binding through `~/.emacs'
by those who like this behaviour.  Or we could make behaviour
of the Home key customizeable.

Quick explanation: in the line

	  some t[>>point<<]ext here

after first evaluation of proposed function we get

	  [>>point<<]some text here

and after second evaluation we get

[>>point<<]	  some text here


Paul


--- indent.el	24 Oct 2004 23:58:43 +0300	1.59
+++ indent.el	14 Nov 2004 23:28:35 +0200	
@@ -329,6 +329,21 @@ line, but does not move past any whitesp
   (if (memq (current-justification) '(center right))
       (skip-chars-forward " \t")))
 
+(defun beginning-of-line-smart (&optional n)
+  "Move to the beginning of the text on this line, or to the beginning of the line.
+More exactly, if the point is already at the beginning of the
+line's text (as defined by `beginning-of-line-text'), it is
+placed at the very beginning of the line.  Otherwise it is moved
+to the text beginning.
+
+With optional argument, different from 1, behave identically to
+`beginning-of-line-text'."
+  (interactive "p")
+  (let ((current-point (point)))
+    (beginning-of-line-text n)
+    (when (= (point) current-point)
+      (beginning-of-line))))
+
 (defvar indent-region-function nil
   "Short cut function to indent region using `indent-according-to-mode'.
 A value of nil means really run `indent-according-to-mode' on each line.")

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

* Re: a simple convenience function
  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:50   ` Paul Pogonyshev
  2004-11-15  6:45 ` Thien-Thi Nguyen
  2004-11-15  9:29 ` Kai Grossjohann
  2 siblings, 2 replies; 14+ messages in thread
From: Miles Bader @ 2004-11-14 23:34 UTC (permalink / raw)
  Cc: emacs-devel

On Sun, Nov 14, 2004 at 11:36:00PM +0200, Paul Pogonyshev wrote:
> I'm not sure this issue wasn't raised already, but what do
> you think about adding this simple function to Emasc? 

There's already `back-to-indentation', bound to M-m by default.

I don't think the repeat-functionality you described seems really worth
adding another function.

-Miles
-- 
"Whatever you do will be insignificant, but it is very important that
 you do it."  Mahatma Ghandi

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

* Re: a simple convenience function
  2004-11-14 23:34 ` Miles Bader
@ 2004-11-15  0:22   ` Lennart Borgman
  2004-11-15  1:49     ` Paul Pogonyshev
  2004-11-15  1:50   ` Paul Pogonyshev
  1 sibling, 1 reply; 14+ messages in thread
From: Lennart Borgman @ 2004-11-15  0:22 UTC (permalink / raw)
  Cc: emacs-devel

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)


----- Original Message ----- 
From: "Miles Bader" <miles@gnu.org>
To: "Paul Pogonyshev" <pogonyshev@gmx.net>
Cc: <emacs-devel@gnu.org>
Sent: Monday, November 15, 2004 12:34 AM
Subject: Re: a simple convenience function


> On Sun, Nov 14, 2004 at 11:36:00PM +0200, Paul Pogonyshev wrote:
> > I'm not sure this issue wasn't raised already, but what do
> > you think about adding this simple function to Emasc?
>
> There's already `back-to-indentation', bound to M-m by default.
>
> I don't think the repeat-functionality you described seems really worth
> adding another function.
>
> -Miles
> -- 
> "Whatever you do will be insignificant, but it is very important that
>  you do it."  Mahatma Ghandi
>
>
> _______________________________________________
> Emacs-devel mailing list
> Emacs-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-devel
>

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

* Re: a simple convenience function
  2004-11-15  0:22   ` Lennart Borgman
@ 2004-11-15  1:49     ` Paul Pogonyshev
  2004-11-15  5:01       ` Dhruva Krishnamurthy
  2004-11-15  7:28       ` Lennart Borgman
  0 siblings, 2 replies; 14+ messages in thread
From: Paul Pogonyshev @ 2004-11-15  1:49 UTC (permalink / raw)
  Cc: emacs-devel, Miles Bader


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

Paul

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

* Re: a simple convenience function
  2004-11-14 23:34 ` Miles Bader
  2004-11-15  0:22   ` Lennart Borgman
@ 2004-11-15  1:50   ` Paul Pogonyshev
  1 sibling, 0 replies; 14+ messages in thread
From: Paul Pogonyshev @ 2004-11-15  1:50 UTC (permalink / raw)
  Cc: Lennart Borgman, emacs-devel


> On Sun, Nov 14, 2004 at 11:36:00PM +0200, Paul Pogonyshev wrote:
> > I'm not sure this issue wasn't raised already, but what do
> > you think about adding this simple function to Emasc?
>
> There's already `back-to-indentation', bound to M-m by default.
>
> I don't think the repeat-functionality you described seems really worth
> adding another function.

I got used to it years ago when I was still working under Windows with
MS Visual Studio.  When I switched to Emacs, it was about the first
things I customized with Elisp.

Paul

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

* Re: a simple convenience function
  2004-11-15  1:49     ` Paul Pogonyshev
@ 2004-11-15  5:01       ` Dhruva Krishnamurthy
  2004-11-15  7:28       ` Lennart Borgman
  1 sibling, 0 replies; 14+ messages in thread
From: Dhruva Krishnamurthy @ 2004-11-15  5:01 UTC (permalink / raw)
  Cc: Lennart Borgman, Miles Bader, emacs-devel

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/

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

* Re: a simple convenience function
  2004-11-14 21:36 a simple convenience function Paul Pogonyshev
  2004-11-14 23:34 ` Miles Bader
@ 2004-11-15  6:45 ` Thien-Thi Nguyen
  2004-11-15  9:29 ` Kai Grossjohann
  2 siblings, 0 replies; 14+ messages in thread
From: Thien-Thi Nguyen @ 2004-11-15  6:45 UTC (permalink / raw)
  Cc: emacs-devel

Paul Pogonyshev <pogonyshev@gmx.net> writes:

   (defun beginning-of-line-smart (&optional n) ...)

see also codeline.el:

http://www.glug.org/people/ttn/software/ttn-pers-elisp/dist-lisp-index.html

it behaves similarly, and additionally in the other direction.

thi

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

* Re: a simple convenience function
  2004-11-15  1:49     ` Paul Pogonyshev
  2004-11-15  5:01       ` Dhruva Krishnamurthy
@ 2004-11-15  7:28       ` Lennart Borgman
  1 sibling, 0 replies; 14+ messages in thread
From: Lennart Borgman @ 2004-11-15  7:28 UTC (permalink / raw)
  Cc: emacs-devel, Drew Adams, Miles Bader

Yes, my intention was to not change the default behaviour for default usage
so to say, but I realize now that a little bit more is needed to achieve
that.

- Lennart


----- Original Message ----- 
From: "Paul Pogonyshev" <pogonyshev@gmx.net>
To: "Lennart Borgman" <lennart.borgman.073@student.lu.se>
Cc: "Miles Bader" <miles@gnu.org>; <emacs-devel@gnu.org>
Sent: Monday, November 15, 2004 2:49 AM
Subject: Re: a simple convenience function



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

Paul

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

* Re: a simple convenience function
  2004-11-14 21:36 a simple convenience function Paul Pogonyshev
  2004-11-14 23:34 ` Miles Bader
  2004-11-15  6:45 ` Thien-Thi Nguyen
@ 2004-11-15  9:29 ` Kai Grossjohann
  2004-11-15 23:14   ` Alex Schroeder
  2 siblings, 1 reply; 14+ messages in thread
From: Kai Grossjohann @ 2004-11-15  9:29 UTC (permalink / raw)


Paul Pogonyshev <pogonyshev@gmx.net> writes:

> +(defun beginning-of-line-smart (&optional n)
> +  "Move to the beginning of the text on this line, or to the beginning of the line.
> +More exactly, if the point is already at the beginning of the
> +line's text (as defined by `beginning-of-line-text'), it is
> +placed at the very beginning of the line.  Otherwise it is moved
> +to the text beginning.
> +
> +With optional argument, different from 1, behave identically to
> +`beginning-of-line-text'."

I used to have something similar, except that I changed the <home> key
to move to beginning of line, then beginning of window, then beginning
of buffer.  But the behavior of that function was different: where it
moved depended on how often you hit the <home> key.  When you first
hit it, it moved to beginning of line, if you then immediately press
it again, it moves to beginning of window, and so on.

I found this to be better because I knew I could always hit <home>
twice to end up at the beginning of the window, and I didn't have to
check whether point was already at the beginning of the line.

But for the proposed binding, it's more difficult: one would expect
C-a to move to the left, so its behavior needs to depend on the
position of point, I think.

What do others think about the tradeoff between the "never move right"
and the "make behavior predictable without looking at text"
constraints?

Kai

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

* Re: a simple convenience function
  2004-11-15  9:29 ` Kai Grossjohann
@ 2004-11-15 23:14   ` Alex Schroeder
  2004-11-15 23:27     ` Lennart Borgman
                       ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Alex Schroeder @ 2004-11-15 23:14 UTC (permalink / raw)


Kai Grossjohann <kai@emptydomain.de> writes:

> What do others think about the tradeoff between the "never move right"
> and the "make behavior predictable without looking at text"
> constraints?

I really like your predictable behavior.  I never thought about it
that way, but now that you put it this way, I think "dwim" in this
situation should be independent of where point is in the text.  It
should depend on what the user did, instead.

I'm not sure I like your "beginning of window" step, however, because
I usually hop through buffers in paragraphs, sexps, or defuns, or
whatever the text-based unit is.  Using a display-based unit is weird.

Alex.
-- 
.O.  http://www.emacswiki.org/alex/
..O  Schroeder's fifth law:
OOO  Never accept more work than you can handle in one night of hacking.

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

* Re: a simple convenience function
  2004-11-15 23:14   ` Alex Schroeder
@ 2004-11-15 23:27     ` Lennart Borgman
  2004-11-16 17:11     ` Kai Grossjohann
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 14+ messages in thread
From: Lennart Borgman @ 2004-11-15 23:27 UTC (permalink / raw)
  Cc: Kai Grossjohann

----- Original Message ----- 
From: "Alex Schroeder" <alex@emacswiki.org>


> Kai Grossjohann <kai@emptydomain.de> writes:
>
> > What do others think about the tradeoff between the "never move right"
> > and the "make behavior predictable without looking at text"
> > constraints?
>
> I really like your predictable behavior.

Agree. I would not be able to use it if it were not predictable. I type
first and look later...

- Lennart

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

* Re: a simple convenience function
  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
  3 siblings, 0 replies; 14+ messages in thread
From: Kai Grossjohann @ 2004-11-16 17:11 UTC (permalink / raw)


Alex Schroeder <alex@emacswiki.org> writes:

> I'm not sure I like your "beginning of window" step, however, because
> I usually hop through buffers in paragraphs, sexps, or defuns, or
> whatever the text-based unit is.  Using a display-based unit is weird.

I only explained what my function did.  After using it for a while, I
found out that I always hit it once or thrice, but never twice.

I also think that perhaps going to the beginning of the defun is a
good idea as an intermediary step.

Kai

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

* Re: a simple convenience function
  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
  3 siblings, 0 replies; 14+ messages in thread
From: Kai Grossjohann @ 2004-11-16 17:14 UTC (permalink / raw)


Alex Schroeder <alex@emacswiki.org> writes:

> Kai Grossjohann <kai@emptydomain.de> writes:
>
>> What do others think about the tradeoff between the "never move right"
>> and the "make behavior predictable without looking at text"
>> constraints?
>
> I really like your predictable behavior.  I never thought about it
> that way, but now that you put it this way, I think "dwim" in this
> situation should be independent of where point is in the text.  It
> should depend on what the user did, instead.

The only problem is that if you always move to the beginning of the
text on the first press, then C-a might move right.  And that is very
strange in left-to-right languages.

Gnus has dwimish C-a in message-mode: It goes to the beginning of the
header text, or to the beginning of the line, when in a message header.
The Gnus behavior is also to move right in some circumstances.  It's
strange.

Kai

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

* Re: a simple convenience function
  2004-11-15 23:14   ` Alex Schroeder
                       ` (2 preceding siblings ...)
  2004-11-16 17:14     ` Kai Grossjohann
@ 2004-11-16 17:20     ` Kai Grossjohann
  3 siblings, 0 replies; 14+ messages in thread
From: Kai Grossjohann @ 2004-11-16 17:20 UTC (permalink / raw)


Alex Schroeder <alex@emacswiki.org> writes:

> I'm not sure I like your "beginning of window" step, however, because
> I usually hop through buffers in paragraphs, sexps, or defuns, or
> whatever the text-based unit is.  Using a display-based unit is weird.

Well, a line is a display-based unit, so having the C-a behavior
depend on the display seems logical.

But I also found out that I never used the beginning of window step.

Kai

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

end of thread, other threads:[~2004-11-16 17:20 UTC | newest]

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

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.