unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Problems with 'd' and 'delete' key
@ 2008-04-20 14:51 saneman
  2008-04-20 15:06 ` Pascal Bourguignon
  0 siblings, 1 reply; 6+ messages in thread
From: saneman @ 2008-04-20 14:51 UTC (permalink / raw)
  To: help-gnu-emacs

I have redefined C-d to comment/uncomment. But when I press delete it 
also inserts a comment (% i latex mode). Is it possible to assign 
something to the key 'd' without change 'delete'?

I have this in my .emacs file:


(global-set-key "\C-d" 'comment-dwim)
(define-key function-key-map [delete] [deletechar])

But delete still inserts a comment instead of deleting a character.


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

* Re: Problems with 'd' and 'delete' key
  2008-04-20 14:51 Problems with 'd' and 'delete' key saneman
@ 2008-04-20 15:06 ` Pascal Bourguignon
  2008-04-20 15:26   ` saneman
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal Bourguignon @ 2008-04-20 15:06 UTC (permalink / raw)
  To: help-gnu-emacs

saneman <ddd@sdf.com> writes:

> I have redefined C-d to comment/uncomment. But when I press delete it
> also inserts a comment (% i latex mode). Is it possible to assign
> something to the key 'd' without change 'delete'?
>
> I have this in my .emacs file:
>
>
> (global-set-key "\C-d" 'comment-dwim)
> (define-key function-key-map [delete] [deletechar])
> But delete still inserts a comment instead of deleting a character.

That's strange.   The doc of define-key doesn't mention vectors for
the def argument.  

I would just write:

    (global-set-key (kbd "C-d") 'comment-dwim)

This shouldn't change the binding of the delete key.
Note that (string= "\C-d" "C-d").


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.


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

* Re: Problems with 'd' and 'delete' key
  2008-04-20 15:06 ` Pascal Bourguignon
@ 2008-04-20 15:26   ` saneman
  2008-04-20 17:22     ` djfiander
  0 siblings, 1 reply; 6+ messages in thread
From: saneman @ 2008-04-20 15:26 UTC (permalink / raw)
  To: help-gnu-emacs

Pascal Bourguignon wrote:
> saneman <ddd@sdf.com> writes:
> 
>> I have redefined C-d to comment/uncomment. But when I press delete it
>> also inserts a comment (% i latex mode). Is it possible to assign
>> something to the key 'd' without change 'delete'?
>>
>> I have this in my .emacs file:
>>
>>
>> (global-set-key "\C-d" 'comment-dwim)
>> (define-key function-key-map [delete] [deletechar])
>> But delete still inserts a comment instead of deleting a character.
> 
> That's strange.   The doc of define-key doesn't mention vectors for
> the def argument.  
> 
> I would just write:
> 
>     (global-set-key (kbd "C-d") 'comment-dwim)
> 
> This shouldn't change the binding of the delete key.
> Note that (string= "\C-d" "C-d").
> 
> 

I have now tried:

(global-set-key (kbd "C-d") 'comment-dwim)

instead but that also changes the delete key. Could it be a bug in 
emacs? I am using a danish keyboard.


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

* Re: Problems with 'd' and 'delete' key
  2008-04-20 15:26   ` saneman
@ 2008-04-20 17:22     ` djfiander
  2008-04-21  7:25       ` saneman
  0 siblings, 1 reply; 6+ messages in thread
From: djfiander @ 2008-04-20 17:22 UTC (permalink / raw)
  To: help-gnu-emacs

On Apr 20, 11:26 am, saneman <d...@sdf.com> wrote:
> Pascal Bourguignon wrote:
> > saneman <d...@sdf.com> writes:
> >> (global-set-key "\C-d" 'comment-dwim)
> >> (define-key function-key-map [delete] [deletechar])
> >> But delete still inserts a comment instead of deleting a character.
>
> > That's strange.   The doc of define-key doesn't mention vectors for
> > the def argument.

Well, I just switched to Emacs and hit C-h k [delete] and was informed
that

        C-d (translated from <delete>) runs the command delete-char

(Personally, I also question the wisdom of remapping a very basic
control character, but let's leave that aside.)

[delete] is translated to C-d by the function-key-map. See also the
comment in bindings.el:

;; Don't do this.  We define <delete> in function-key-map instead.
;(define-key global-map [delete] 'backward-delete-char)

So, in order for everything to work the way you want, you need to put
this partially untested code in your .emacs file

;; define [delete] in global-map with what it would be if it weren't
being mapped by the function-key-map
(let ((delete-mapping (lookup-key function-key-map [delete])))
  (when delete-mapping
    (define-key global-map [delete] (lookup-key (current-global-map)
delete-mapping))))

;; Assuming you have the delete mapping defined above, you don't
really need to do this, it looks like
(define-key function-key-map [delete] nil)

(global-set-key "\C-d" 'comment-dwim)

But don't. Really.


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

* Re: Problems with 'd' and 'delete' key
  2008-04-20 17:22     ` djfiander
@ 2008-04-21  7:25       ` saneman
  2008-04-21  7:29         ` saneman
  0 siblings, 1 reply; 6+ messages in thread
From: saneman @ 2008-04-21  7:25 UTC (permalink / raw)
  To: help-gnu-emacs

djfiander wrote:
> On Apr 20, 11:26 am, saneman <d...@sdf.com> wrote:
>> Pascal Bourguignon wrote:
>>> saneman <d...@sdf.com> writes:
>>>> (global-set-key "\C-d" 'comment-dwim)
>>>> (define-key function-key-map [delete] [deletechar])
>>>> But delete still inserts a comment instead of deleting a character.
>>> That's strange.   The doc of define-key doesn't mention vectors for
>>> the def argument.
> 
> Well, I just switched to Emacs and hit C-h k [delete] and was informed
> that
> 
>         C-d (translated from <delete>) runs the command delete-char
> 
> (Personally, I also question the wisdom of remapping a very basic
> control character, but let's leave that aside.)
> 
> [delete] is translated to C-d by the function-key-map. See also the
> comment in bindings.el:
> 
> ;; Don't do this.  We define <delete> in function-key-map instead.
> ;(define-key global-map [delete] 'backward-delete-char)
> 
> So, in order for everything to work the way you want, you need to put
> this partially untested code in your .emacs file
> 
> ;; define [delete] in global-map with what it would be if it weren't
> being mapped by the function-key-map
> (let ((delete-mapping (lookup-key function-key-map [delete])))
>   (when delete-mapping
>     (define-key global-map [delete] (lookup-key (current-global-map)
> delete-mapping))))
> 
> ;; Assuming you have the delete mapping defined above, you don't
> really need to do this, it looks like
> (define-key function-key-map [delete] nil)
> 
> (global-set-key "\C-d" 'comment-dwim)
> 
> But don't. Really.


It almost seems to work. But when I press delete it works as backspace 
(deleting backward). Is there someway to get the normal delete key 
behavior where the cursor don't move but deletes characters in front?

I think the command is called delete-char but where should it be added?


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

* Re: Problems with 'd' and 'delete' key
  2008-04-21  7:25       ` saneman
@ 2008-04-21  7:29         ` saneman
  0 siblings, 0 replies; 6+ messages in thread
From: saneman @ 2008-04-21  7:29 UTC (permalink / raw)
  To: help-gnu-emacs

  > It almost seems to work. But when I press delete it works as backspace
> (deleting backward). Is there someway to get the normal delete key 
> behavior where the cursor don't move but deletes characters in front?
> 
> I think the command is called delete-char but where should it be added?

I now get the correct behavior with just these two lines:

(define-key global-map [delete] 'delete-char)
(global-set-key "\C-d" 'comment-dwim)


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

end of thread, other threads:[~2008-04-21  7:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-20 14:51 Problems with 'd' and 'delete' key saneman
2008-04-20 15:06 ` Pascal Bourguignon
2008-04-20 15:26   ` saneman
2008-04-20 17:22     ` djfiander
2008-04-21  7:25       ` saneman
2008-04-21  7:29         ` saneman

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