unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* DWIM for the TAB key
@ 2005-02-16  1:42 Oliver Scholz
  2005-02-16  2:03 ` Oliver Scholz
  2005-02-16 17:16 ` rbielaws
  0 siblings, 2 replies; 5+ messages in thread
From: Oliver Scholz @ 2005-02-16  1:42 UTC (permalink / raw)


Reading a thread on emacs-devel, I thought that maybe others would
also like what I have been using for quite a while:

(defun egoge-tab-dwim ()
  "Indent or complete depending on the context.
If point is at the beginning of a line or if all characters
between point and the beginning of the line are whitespace
characters, indent that line. Otherwise complete the symbol at
point."
  (interactive)
  (if (or (bolp)
          (save-excursion (backward-char 1)
                          (looking-at "[[:blank:]]")))
      (indent-according-to-mode)
    (if (memq major-mode '(emacs-lisp-mode
                           lisp-interaction-mode
                           inferior-emacs-lisp-mode))
        (lisp-complete-symbol)
      (complete-symbol))))

(define-key global-map [tab] 'egoge-tab-dwim)

    Oliver
-- 
28 Pluviôse an 213 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: DWIM for the TAB key
  2005-02-16  1:42 DWIM for the TAB key Oliver Scholz
@ 2005-02-16  2:03 ` Oliver Scholz
  2005-02-16 17:16 ` rbielaws
  1 sibling, 0 replies; 5+ messages in thread
From: Oliver Scholz @ 2005-02-16  2:03 UTC (permalink / raw)


Oliver Scholz <alkibiades@gmx.de> writes:

> Reading a thread on emacs-devel, I thought that maybe others would
> also like what I have been using for quite a while:
>
> (defun egoge-tab-dwim ()
[...]

> (define-key global-map [tab] 'egoge-tab-dwim)

Well, I realise that this keybinding is actually not what I am using,
I am using

  (define-key emacs-lisp-mode-map [tab] 'egoge-tab-dwim)

As a global binding this function would need more work ... but ... too
lazy now ... must ... rest ...

    Oliver
-- 
28 Pluviôse an 213 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: DWIM for the TAB key
  2005-02-16  1:42 DWIM for the TAB key Oliver Scholz
  2005-02-16  2:03 ` Oliver Scholz
@ 2005-02-16 17:16 ` rbielaws
  2005-02-17 13:16   ` Oliver Scholz
  1 sibling, 1 reply; 5+ messages in thread
From: rbielaws @ 2005-02-16 17:16 UTC (permalink / raw)



Oliver Scholz wrote:
> Reading a thread on emacs-devel, I thought that maybe others would
> also like what I have been using for quite a while:
>
> (defun egoge-tab-dwim ()
>   "Indent or complete depending on the context.
> If point is at the beginning of a line or if all characters
> between point and the beginning of the line are whitespace
> characters, indent that line. Otherwise complete the symbol at
> point."
>   (interactive)

This code doesn't seem to do what the comments say it should.

>   (if (or (bolp)
>           (save-excursion (backward-char 1)
>                           (looking-at "[[:blank:]]")))

    (if (save-excursion (skip-syntax-backward "-")
                        (bolp))

>       (indent-according-to-mode)
>     (if (memq major-mode '(emacs-lisp-mode
>                            lisp-interaction-mode
>                            inferior-emacs-lisp-mode))
>         (lisp-complete-symbol)
>       (complete-symbol))))
>
> (define-key global-map [tab] 'egoge-tab-dwim)
>
>     Oliver
> --
> 28 Pluviôse an 213 de la Révolution
> Liberté, Egalité, Fraternité!

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

* Re: DWIM for the TAB key
  2005-02-16 17:16 ` rbielaws
@ 2005-02-17 13:16   ` Oliver Scholz
  2005-02-17 14:40     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Oliver Scholz @ 2005-02-17 13:16 UTC (permalink / raw)


"rbielaws@i1.net" <rbielaws@i1.net> writes:

> Oliver Scholz wrote:
[...]
>> (defun egoge-tab-dwim ()
>>   "Indent or complete depending on the context.
>> If point is at the beginning of a line or if all characters
>> between point and the beginning of the line are whitespace
>> characters, indent that line. Otherwise complete the symbol at
>> point."
>>   (interactive)
>
> This code doesn't seem to do what the comments say it should.

Right. The code just checks for a single whitespace character. I wrote
the doc string before the body of the function and changed my mind
when writing the latter. I don't know yet what's better: check whether
everything before point is blank or whether there is a single blank
before point, i.e. whether this is a bug or a doc-bug. Of course
completion is rather pointless if there is no symbol at point ...

    Oliver
-- 
29 Pluviôse an 213 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: DWIM for the TAB key
  2005-02-17 13:16   ` Oliver Scholz
@ 2005-02-17 14:40     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2005-02-17 14:40 UTC (permalink / raw)


Oliver Scholz <alkibiades@gmx.de> writes:

> pointless if there is no symbol at point ...

it seems to me it would make sense that we talk
about "before", not "at", point.

thi

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

end of thread, other threads:[~2005-02-17 14:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-16  1:42 DWIM for the TAB key Oliver Scholz
2005-02-16  2:03 ` Oliver Scholz
2005-02-16 17:16 ` rbielaws
2005-02-17 13:16   ` Oliver Scholz
2005-02-17 14:40     ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).