unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Two Emacs challenges
@ 2006-06-16 20:03 Leon
  2006-06-16 20:15 ` Lennart Borgman
  2006-06-17  3:42 ` William Xu
  0 siblings, 2 replies; 8+ messages in thread
From: Leon @ 2006-06-16 20:03 UTC (permalink / raw)


Dear all,

I found two useful key bindings but they seems not obvious to achieve.

(1) Ctrl+Tab & Alt+Tab

Since most window managers have used Alt+Tab for switching windows,
Alt+Tab key bindings is useless in Emacs running in X. Is there
something I can set in ~/.emacs so that Alt+Tab will be remapped to
Ctrl+Tab? For example, if AUCTeX has bound <M-tab> to
TeX-complete-symbol, the function should be *automatically* bound to
<C-tab> when I enter LaTeX-mode.

(2) pairs

How to bind keys such as (, [, {, " etc to perform such function

When type once, it will insert a pair while twice insert itself for
example: `[' will insert `[]' and leave the cursor in the middle while
`[[' will insert `['?


Thank you all.
-- 
Leon

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

* Re: Two Emacs challenges
  2006-06-16 20:03 Two Emacs challenges Leon
@ 2006-06-16 20:15 ` Lennart Borgman
  2006-06-16 20:21   ` Lennart Borgman
  2006-06-16 20:21   ` Leon
  2006-06-17  3:42 ` William Xu
  1 sibling, 2 replies; 8+ messages in thread
From: Lennart Borgman @ 2006-06-16 20:15 UTC (permalink / raw)
  Cc: help-gnu-emacs

Leon wrote:
> Dear all,
>
> I found two useful key bindings but they seems not obvious to achieve.
>
> (1) Ctrl+Tab & Alt+Tab
>
> Since most window managers have used Alt+Tab for switching windows,
> Alt+Tab key bindings is useless in Emacs running in X. Is there
> something I can set in ~/.emacs so that Alt+Tab will be remapped to
> Ctrl+Tab? For example, if AUCTeX has bound <M-tab> to
> TeX-complete-symbol, the function should be *automatically* bound to
> <C-tab> when I enter LaTeX-mode.
>   
 From the manual to the next version of Emacs (22):

   The character `M-<TAB>' runs a command to complete the partial
symbol before point against the set of meaningful symbol names.  This
command inserts at point any additional characters that it can
determine from the partial name.  (If your window manager defines
`M-<TAB>' to switch windows, you can type `<ESC> <TAB>' or `C-M-i'.)

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

* Re: Two Emacs challenges
  2006-06-16 20:15 ` Lennart Borgman
@ 2006-06-16 20:21   ` Lennart Borgman
  2006-06-16 20:21   ` Leon
  1 sibling, 0 replies; 8+ messages in thread
From: Lennart Borgman @ 2006-06-16 20:21 UTC (permalink / raw)
  Cc: help-gnu-emacs, Leon

Lennart Borgman wrote:
> Leon wrote:
>> Dear all,
>>
>> I found two useful key bindings but they seems not obvious to achieve.
>>
>> (1) Ctrl+Tab & Alt+Tab
>>
>> Since most window managers have used Alt+Tab for switching windows,
>> Alt+Tab key bindings is useless in Emacs running in X. Is there
>> something I can set in ~/.emacs so that Alt+Tab will be remapped to
>> Ctrl+Tab? For example, if AUCTeX has bound <M-tab> to
>> TeX-complete-symbol, the function should be *automatically* bound to
>> <C-tab> when I enter LaTeX-mode.
>>   
> From the manual to the next version of Emacs (22):
>
>   The character `M-<TAB>' runs a command to complete the partial
> symbol before point against the set of meaningful symbol names.  This
> command inserts at point any additional characters that it can
> determine from the partial name.  (If your window manager defines
> `M-<TAB>' to switch windows, you can type `<ESC> <TAB>' or `C-M-i'.)
Forgot to say that this is actually not quite correct. The window 
manager knows nothing about M (Meta) which is Emacs specific. The window 
manager uses Alt-Tab. However Emacs might have bound Meta to Alt.

So another option might be to move Meta to some other key that you can 
use conveniently. (I myself have Meta on the windows keys.)

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

* Re: Two Emacs challenges
  2006-06-16 20:15 ` Lennart Borgman
  2006-06-16 20:21   ` Lennart Borgman
@ 2006-06-16 20:21   ` Leon
  1 sibling, 0 replies; 8+ messages in thread
From: Leon @ 2006-06-16 20:21 UTC (permalink / raw)


Lennart Borgman <lennart.borgman.073@student.lu.se> writes:

> Leon wrote:
>> Dear all,
>>
>> I found two useful key bindings but they seems not obvious to achieve.
>>
>> (1) Ctrl+Tab & Alt+Tab
>>
>> Since most window managers have used Alt+Tab for switching windows,
>> Alt+Tab key bindings is useless in Emacs running in X. Is there
>> something I can set in ~/.emacs so that Alt+Tab will be remapped to
>> Ctrl+Tab? For example, if AUCTeX has bound <M-tab> to
>> TeX-complete-symbol, the function should be *automatically* bound to
>> <C-tab> when I enter LaTeX-mode.
>>   
> From the manual to the next version of Emacs (22):
>
>   The character `M-<TAB>' runs a command to complete the partial
> symbol before point against the set of meaningful symbol names.  This
> command inserts at point any additional characters that it can
> determine from the partial name.  (If your window manager defines
> `M-<TAB>' to switch windows, you can type `<ESC> <TAB>' or `C-M-i'.)

Thanks for answering. Actually I have been using '<ESC> <TAB>'.

-- 
Leon

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

* Re: Two Emacs challenges
       [not found] <mailman.2952.1150488218.9609.help-gnu-emacs@gnu.org>
@ 2006-06-17  0:26 ` Joe Fineman
  2006-06-17 10:07   ` Leon
  0 siblings, 1 reply; 8+ messages in thread
From: Joe Fineman @ 2006-06-17  0:26 UTC (permalink / raw)


Leon <sdl.web@gmail.com> writes:

> How to bind keys such as (, [, {, " etc to perform such function
>
> When type once, it will insert a pair while twice insert itself for
> example: `[' will insert `[]' and leave the cursor in the middle
> while `[[' will insert `['?

There are, IIRC, special keyings in the programming-language modes for
doing the first part of this (I can't find them in the manual at the
moment).  For text mode, I have done the following:

----------------------------------------------------------------------
(defun close-paren ()
  (interactive)
  (insert "()")
  (forward-char -1))

(defun close-bracket ()
  (interactive)
  (insert "[]")
  (forward-char -1))

(defun close-brace ()
  (interactive)
  (insert "{}")
  (forward-char -1))

(defun close-quote ()
  (interactive)
  (insert "\"\"")
  (forward-char -1))

(global-set-key "(" 'close-paren)
(global-set-key "[" 'close-bracket)
(global-set-key "{" 'close-brace)
(global-set-key "\"" 'close-quote)
----------------------------------------------------------------------

To get past the right fence in the most usual contexts, I have done
the following:

----------------------------------------------------------------------
(defun jump-fence (n)
  "If this char is doubled before a right fence, jump over & insert it once."
  (interactive "p")
  (if (> n 1)
      (self-insert-command n)
    (let ((origin (point)))
      (self-insert-command 1)
      (if (= (point) (1+ origin))
	  (progn
	    (if (looking-at "[])\"]\\|=[0-9][A-Z]\\|\\(\^[.\\)+")
		(if (= (char-after (- (point) 2)) (preceding-char))
		    (progn (delete-char -2)
			   (goto-char (- (match-end 0) 2))
			   (self-insert-command 1))))))
      )))

(global-set-key "." 'jump-fence)
(global-set-key "," 'jump-fence)
(global-set-key ";" 'jump-fence)
(global-set-key ":" 'jump-fence)
(global-set-key "?" 'jump-fence)
(global-set-key "!" 'jump-fence)
(global-set-key " " 'jump-fence)
----------------------------------------------------------------------

I had not thought of the second part of your request.  If I want only
the left fence, I just delete the right one.

N.B.  I am not a programmer, so I am sure all this is dreadfully
naive.
-- 
---  Joe Fineman    joe_f@verizon.net

||:  The tragedy is not what we suffer, but what we miss.  :||

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

* Re: Two Emacs challenges
  2006-06-16 20:03 Two Emacs challenges Leon
  2006-06-16 20:15 ` Lennart Borgman
@ 2006-06-17  3:42 ` William Xu
  2006-06-17  9:42   ` Leon
  1 sibling, 1 reply; 8+ messages in thread
From: William Xu @ 2006-06-17  3:42 UTC (permalink / raw)


Leon <sdl.web@gmail.com> writes:

[...]

> (2) pairs
>
> How to bind keys such as (, [, {, " etc to perform such function
>
> When type once, it will insert a pair while twice insert itself for
> example: `[' will insert `[]' and leave the cursor in the middle 

Set this, 

(setq skeleton-pair t)
(global-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "{") 'skeleton-pair-insert-maybe)

> while `[[' will insert `['?

i don't understand why you would like this. Suppose we want to write a
nested list, like '((a) (b)), same insert scheme is still useful.

-- 
William

Battle, n.:
	A method of untying with the teeth a political knot that
	will not yield to the tongue.
		-- Ambrose Bierce

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

* Re: Two Emacs challenges
  2006-06-17  3:42 ` William Xu
@ 2006-06-17  9:42   ` Leon
  0 siblings, 0 replies; 8+ messages in thread
From: Leon @ 2006-06-17  9:42 UTC (permalink / raw)


William Xu <william.xwl@gmail.com> writes:

> Leon <sdl.web@gmail.com> writes:
>
> [...]
>
>> (2) pairs
>>
>> How to bind keys such as (, [, {, " etc to perform such function
>>
>> When type once, it will insert a pair while twice insert itself for
>> example: `[' will insert `[]' and leave the cursor in the middle 
>
> Set this, 
>
> (setq skeleton-pair t)
> (global-set-key (kbd "(") 'skeleton-pair-insert-maybe)
> (global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
> (global-set-key (kbd "{") 'skeleton-pair-insert-maybe)
>

This is a very nice function. Thanks.

>> while `[[' will insert `['?
>
> i don't understand why you would like this. Suppose we want to write a
> nested list, like '((a) (b)), same insert scheme is still useful.

Sometimes I just want to insert a missing ( or [ etc before a word or
something. But now skeleton-pair-insert-maybe can handle this well.

-- 
Leon

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

* Re: Two Emacs challenges
  2006-06-17  0:26 ` Joe Fineman
@ 2006-06-17 10:07   ` Leon
  0 siblings, 0 replies; 8+ messages in thread
From: Leon @ 2006-06-17 10:07 UTC (permalink / raw)


Joe Fineman <joe_f@verizon.net> writes:

> Leon <sdl.web@gmail.com> writes:
>
>> How to bind keys such as (, [, {, " etc to perform such function
>>
>> When type once, it will insert a pair while twice insert itself for
>> example: `[' will insert `[]' and leave the cursor in the middle
>> while `[[' will insert `['?
>
> There are, IIRC, special keyings in the programming-language modes for
> doing the first part of this (I can't find them in the manual at the
> moment).  For text mode, I have done the following:
>
> ----------------------------------------------------------------------
> (defun close-paren ()
>   (interactive)
>   (insert "()")
>   (forward-char -1))
>
> (defun close-bracket ()
>   (interactive)
>   (insert "[]")
>   (forward-char -1))
>
> (defun close-brace ()
>   (interactive)
>   (insert "{}")
>   (forward-char -1))
>
> (defun close-quote ()
>   (interactive)
>   (insert "\"\"")
>   (forward-char -1))
>
> (global-set-key "(" 'close-paren)
> (global-set-key "[" 'close-bracket)
> (global-set-key "{" 'close-brace)
> (global-set-key "\"" 'close-quote)
> ----------------------------------------------------------------------
>
> To get past the right fence in the most usual contexts, I have done
> the following:
>
> ----------------------------------------------------------------------
> (defun jump-fence (n)
>   "If this char is doubled before a right fence, jump over & insert it once."
>   (interactive "p")
>   (if (> n 1)
>       (self-insert-command n)
>     (let ((origin (point)))
>       (self-insert-command 1)
>       (if (= (point) (1+ origin))
> 	  (progn
> 	    (if (looking-at "[])\"]\\|=[0-9][A-Z]\\|\\(\^[.\\)+")
> 		(if (= (char-after (- (point) 2)) (preceding-char))
> 		    (progn (delete-char -2)
> 			   (goto-char (- (match-end 0) 2))
> 			   (self-insert-command 1))))))
>       )))
>
> (global-set-key "." 'jump-fence)
> (global-set-key "," 'jump-fence)
> (global-set-key ";" 'jump-fence)
> (global-set-key ":" 'jump-fence)
> (global-set-key "?" 'jump-fence)
> (global-set-key "!" 'jump-fence)
> (global-set-key " " 'jump-fence)
> ----------------------------------------------------------------------
>
> I had not thought of the second part of your request.  If I want only
> the left fence, I just delete the right one.
>
> N.B.  I am not a programmer, so I am sure all this is dreadfully
> naive.

Thank you for sharing. I just tried out skeleton-pair-insert-maybe as
suggested by William and it's great.

-- 
Leon

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

end of thread, other threads:[~2006-06-17 10:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-16 20:03 Two Emacs challenges Leon
2006-06-16 20:15 ` Lennart Borgman
2006-06-16 20:21   ` Lennart Borgman
2006-06-16 20:21   ` Leon
2006-06-17  3:42 ` William Xu
2006-06-17  9:42   ` Leon
     [not found] <mailman.2952.1150488218.9609.help-gnu-emacs@gnu.org>
2006-06-17  0:26 ` Joe Fineman
2006-06-17 10:07   ` Leon

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