[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to rebind keys "C-j" to join-line -- SOLVED!

From: Alex Wei
Subject: Re: How to rebind keys "C-j" to join-line -- SOLVED!
Date: Wed, 8 Aug 2007 10:27:06 +0800

Hi H. Dieter Wilhelm
Thanks for disgussing, your understandings are almost right.
C-o  -- Yes, just  C-e <RET>, the same effect as Vim's  o command
C--   -- Kill whole line, same as  C-a C-k C-k, kill whole line along with the last carriage return.
C-=  -- Yes, I define it as copy whole line, the same effect as Vim's  yy command
C-.  -- Why binding this to set-mark-command, and not C-SPC, because It was defined by Windows to activate IME.
Why hook it up? Because other scripts override my key bindings after Emacs startup,  .emacs was executed the first.
Appending my codes for your reference.
(defun copy-whole-line ()
  "copy line"
  (setq end-pos (if (< (line-end-position) (point-max)) (+ 1 (line-end-position)) (point-max)))
  (copy-region-as-kill (line-beginning-position) end-pos)
  (message "line copied.")
(defun kill-whole-line ()
  "cut line"
  (setq end-pos (if (< (line-end-position) (point-max)) (+ 1 (line-end-position)) (point-max)))
  (kill-region (line-beginning-position) end-pos)
(defun open-newline ()
  "open newline below and place the cursor at newline."
  (goto-char (line-end-position))
Best Regards
Alex Wei
Sierra Atlantic
----- Original Message -----
Sent: Wednesday, August 08, 2007 4:36 AM
Subject: Re: How to rebind keys "C-j" to join-line -- SOLVED!

"Alex Wei" <address@hidden> writes:

> Hi all

> I've figured out how to secure binding my keys :D , I found two hooks that will
> guarantee my key-bindings will not be overrided.

> (defun my-key-binding ()
>   "Customize my key bindings after Emacs startup."
>   (interactive)
>   ;; Key
> bindings                                                              
>   (local-set-key (kbd "<RET>") 'newline-and-indent)
>   (local-set-key (kbd "C-.") 'set-mark-command)

Why not the standard binding (C-SPC)?

>   (local-set-key (kbd "C--") 'kill-whole-line)

the same here C-S-backspace? (OK, I answer it myself: One needs three
keys.)  But you are restricting yourself to M-- and C-u- for negative
prefix arguments.

>   (local-set-key (kbd "C-=") 'copy-whole-line)

Yes, this is a function I'm also missing badly in Emacs.

>   (local-set-key (kbd "C-o") 'open-newline)

What is open-newline, something like C-e RET?

>   (local-set-key (kbd "C-j") 'join-line)

As I said M-^ is not so bad either ;-)

> (add-hook 'emacs-startup-hook 'my-key-binding)
> (add-hook 'change-major-mode-hook 'my-key-binding)

Sorry I do not know these hooks, but wouldn't for example:

(global-set-key "\C-o" 'open-newline)

in your .emacs have the same effect without adding hooks?

> Thanks anyway!

You are very welcome.

    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

reply via email to

[Prev in Thread] Current Thread [Next in Thread]