From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Alex Wei" Newsgroups: gmane.emacs.help Subject: Re: How to rebind keys "C-j" to join-line -- SOLVED! Date: Wed, 8 Aug 2007 10:27:06 +0800 Message-ID: References: <1EA8C5CAFEE34474B0BC8809A468377F@array8f42e753d><87r6mkngx6.fsf@debby.local.net><87ejigjs46.fsf@debby.local.net> <87abt3jd50.fsf@debby.local.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0224556237==" X-Trace: sea.gmane.org 1186540057 17085 80.91.229.12 (8 Aug 2007 02:27:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Aug 2007 02:27:37 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Dieter Wilhelm" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 08 04:27:35 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IIbGo-0001Bl-LN for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Aug 2007 04:27:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IIbGn-0000Fu-PY for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Aug 2007 22:27:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IIbGL-0000Ay-Oh for help-gnu-emacs@gnu.org; Tue, 07 Aug 2007 22:27:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IIbGK-0000AS-Se for help-gnu-emacs@gnu.org; Tue, 07 Aug 2007 22:27:05 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IIbGK-0000AM-F3 for help-gnu-emacs@gnu.org; Tue, 07 Aug 2007 22:27:04 -0400 Original-Received: from w98.arrayinc.com ([207.190.196.98] helo=barracuda.arrayinc.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IIbGJ-0006pM-Oa for help-gnu-emacs@gnu.org; Tue, 07 Aug 2007 22:27:04 -0400 X-ASG-Debug-ID: 1186540016-105300080000-2yy5ZX X-Barracuda-URL: http://172.22.0.241:8000/cgi-bin/mark.cgi X-Barracuda-Connect: unknown[59.37.5.20] X-Barracuda-Start-Time: 1186540016 Original-Received: from array8f42e753d (unknown [59.37.5.20]) by barracuda.arrayinc.com (Spam Firewall) with ESMTP id 0E2256213; Tue, 7 Aug 2007 22:26:58 -0400 (EDT) X-ASG-Orig-Subj: Re: How to rebind keys "C-j" to join-line -- SOLVED! X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 12.0.1184 X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1184 X-Barracuda-Virus-Scanned: by Barracuda Spam Firewall at arrayinc.com X-Detected-Kernel: Linux 2.4-2.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:46392 Archived-At: This is a multi-part message in MIME format. --===============0224556237== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0073_01C7D9A6.AB3ABB60" This is a multi-part message in MIME format. ------=_NextPart_000_0073_01C7D9A6.AB3ABB60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi H. Dieter Wilhelm Thanks for disgussing, your understandings are almost right. for C-o -- Yes, just C-e , 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-=3D -- 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.=20 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" (interactive) (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" (interactive) (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." (interactive) (goto-char (line-end-position)) (newline-and-indent) =20 ) Best Regards Alex Wei=20 Sierra Atlantic ----- Original Message -----=20 From: Dieter Wilhelm=20 To: Alex Wei=20 Cc: help-gnu-emacs@gnu.org=20 Sent: Wednesday, August 08, 2007 4:36 AM Subject: Re: How to rebind keys "C-j" to join-line -- SOLVED! "Alex Wei" writes: > Hi all > =20 > 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. > =20 > (defun my-key-binding () > "Customize my key bindings after Emacs startup." > (interactive) > ;; Key > bindings = =20 > (local-set-key (kbd "") '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-=3D") '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. --=20 Best wishes H. Dieter Wilhelm Darmstadt, Germany ------=_NextPart_000_0073_01C7D9A6.AB3ABB60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi H. Dieter Wilhelm
Thanks for disgussing, your understandings are almost right.
 
for
C-o  -- Yes, just  C-e <RET>, the same effect as=20 Vim's  o command
C--   -- Kill whole line, same as  C-a C-k C-k, kill = whole=20 line along with the last carriage return.
C-=3D  -- Yes, I define it as copy whole line, the same effect = as=20 Vim's  yy command
C-.  -- Why binding this to set-mark-command, and not C-SPC, = because=20 It was defined by Windows to activate IME.
 
Why hook it up? Because other scripts override my key bindings = after Emacs=20 startup,  .emacs was executed the first.
Appending my codes for your reference.
 
(defun copy-whole-line ()
  "copy line"
 =20 (interactive)
  (setq end-pos (if (< (line-end-position) = (point-max))=20 (+ 1 (line-end-position)) (point-max)))
  (copy-region-as-kill=20 (line-beginning-position) end-pos)
  (message "line = copied.")
)
 
(defun kill-whole-line ()
  "cut line"
 =20 (interactive)
  (setq end-pos (if (< (line-end-position) = (point-max))=20 (+ 1 (line-end-position)) (point-max)))
  (kill-region=20 (line-beginning-position) end-pos)
)
 
(defun open-newline ()
  "open newline below and place the = cursor=20 at newline."
  (interactive)
  (goto-char=20 (line-end-position))
  (newline-and-indent) 
)
 
Best Regards
 
Alex Wei
Sierra Atlantic
----- Original Message -----
From:=20 Dieter Wilhelm
Cc: help-gnu-emacs@gnu.org =
Sent: Wednesday, August 08, = 2007 4:36=20 AM
Subject: Re: How to rebind keys = "C-j" to=20 join-line -- SOLVED!

"Alex Wei" <swei@arrayinc.com> = writes:

>=20 Hi all

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

> (defun my-key-binding = ()
>  =20 "Customize my key bindings after Emacs startup."
>  =20 (interactive)
>   ;; Key
>=20 = bindings           = ;            =             &= nbsp;           &n= bsp;           &nb= sp;  =20
>   (local-set-key (kbd "<RET>")=20 'newline-and-indent)
>   (local-set-key (kbd "C-.")=20 'set-mark-command)

Why not the standard binding=20 (C-SPC)?

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

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

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

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

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

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

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

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

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

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

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

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

> Thanks=20 anyway!

You are very welcome.

--
    = Best=20 wishes

    H. Dieter = Wilhelm
   =20 Darmstadt, Germany ------=_NextPart_000_0073_01C7D9A6.AB3ABB60-- --===============0224556237== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ help-gnu-emacs mailing list help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --===============0224556237==--