From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dhruva Krishnamurthy Newsgroups: gmane.emacs.devel Subject: Re: a simple convenience function Date: Mon, 15 Nov 2004 10:31:29 +0530 Message-ID: <68c73b1a041114210121be2c58@mail.gmail.com> References: <200411142336.00131.pogonyshev@gmx.net> <20041114233449.GC12968@fencepost> <001001c4caa9$5105b9b0$0200a8c0@sedrcw11488> <200411150349.57864.pogonyshev@gmx.net> Reply-To: Dhruva Krishnamurthy NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1100494935 7982 80.91.229.6 (15 Nov 2004 05:02:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 15 Nov 2004 05:02:15 +0000 (UTC) Cc: Lennart Borgman , Miles Bader , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 15 06:02:07 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CTZ0B-0001IH-00 for ; Mon, 15 Nov 2004 06:02:07 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CTZ8r-0007PD-4k for ged-emacs-devel@m.gmane.org; Mon, 15 Nov 2004 00:11:05 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CTZ8P-0007Cf-6Y for emacs-devel@gnu.org; Mon, 15 Nov 2004 00:10:37 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CTZ8N-0007Bc-TM for emacs-devel@gnu.org; Mon, 15 Nov 2004 00:10:36 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CTZ8N-0007BB-Mh for emacs-devel@gnu.org; Mon, 15 Nov 2004 00:10:35 -0500 Original-Received: from [64.233.184.204] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CTYzZ-0005qh-Vt for emacs-devel@gnu.org; Mon, 15 Nov 2004 00:01:30 -0500 Original-Received: by wproxy.gmail.com with SMTP id 67so512012wri for ; Sun, 14 Nov 2004 21:01:29 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=KLCCAr/yedKV2GAp2APOzTgv8BRilZKx0e+W9U6SGLdi8avjzAMWrk1DELiuBAxScK3qAXQOTilXqTjd5ej8xR2cBLn7ROR9Dd/H5Bo+0EiO15reT3QKFYQl7Wuhx1uaRhZo2t1olrnQR4A8zj0jtCxB5Bs0KusNfkA8E8OWF+s= Original-Received: by 10.54.43.44 with SMTP id q44mr102424wrq; Sun, 14 Nov 2004 21:01:29 -0800 (PST) Original-Received: by 10.54.53.46 with HTTP; Sun, 14 Nov 2004 21:01:29 -0800 (PST) Original-To: Paul Pogonyshev In-Reply-To: <200411150349.57864.pogonyshev@gmx.net> X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:29855 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:29855 Hello, On Mon, 15 Nov 2004 03:49:57 +0200, Paul Pogonyshev wrote: > > > > > Though I found the behaviour suggested by Paul much more mnemonic when > > bound to the Home key. It is also found in some other editors. > > > > - Lennart > > > > PS: Maybe I should write it as > > > > (defun home-or-back-to-indentation() > > (interactive) > > (if (bolp) (back-to-indentation) (beginning-of-line))) > > > > (define-key global-map [home] 'home-or-back-to-indentation) > > Perhaps, but this way you get it the way round: it will first jump > to the beginning of line and then to the beginning of the text. > I have a slightly fancy stuff which I use: On first hit on HOME, it finds whether it is closer to beginning of line or begining of text and jumps to the closer. Same with end of line. An experienced elisp geek could clean up significantly... I am learning to walk/crawl in the elisp ground. ;;----------------------------------------------------------------------------- ;; Intelligent HOME to toggle between 1st text and ZERO column ;;----------------------------------------------------------------------------- (defun intelli-home() "User method to toggle between 1st text and ZERO column" (interactive) (catch 'ret (let ((pos (point)) (blpos (line-beginning-position)) (btpos 0)) ;; If at begin of line (if (= blpos pos) (progn (beginning-of-line-text) (throw 'ret t))) (beginning-of-line-text) (setq btpos (point)) ;; If at begin of text (if (= btpos pos) (progn (beginning-of-line) (throw 'ret t))) ;; Cursor after first text (if (> pos btpos) (throw 'ret t)) ;; Cursor in between begin of line and first text ;; Closer to first text (if (> (- pos blpos) (- btpos pos)) (throw 'ret t)) ;; Closer to begin line (if (or (< (- pos blpos) (- btpos pos)) (= (- pos blpos) (- btpos pos))) (progn (beginning-of-line) (throw 'ret t)))))) ;;----------------------------------------------------------------------------- ;; Move to end of line text (as beginning-of-line-text) ;;----------------------------------------------------------------------------- (defun end-of-line-text() "User method to simulate beginning-of-line-text for end of line" (interactive) (end-of-line) (while (looking-at "[ \t\n]+") (backward-char 1))) ;;----------------------------------------------------------------------------- ;; Intelligent END to toggle between Last text and Last column ;;----------------------------------------------------------------------------- (defun intelli-end() "User method to toggle between Last text and Last column" (interactive) (catch 'ret (let ((pos (point)) (elpos (line-end-position)) (etpos 0)) ;; If at begin of line (if (= elpos pos) (progn (end-of-line-text) (throw 'ret t))) (end-of-line) (setq etpos (point)) ;; If at begin of text (if (= etpos pos) (progn (end-of-line) (throw 'ret t))) ;; Cursor after first text (if (< pos etpos) (throw 'ret t)) ;; Cursor in between begin of line and first text ;; Closer to first text (if (< (- pos elpos) (- etpos pos)) (throw 'ret t)) ;; Closer to begin line (if (or (> (- pos elpos) (- etpos pos)) (= (- pos elpos) (- etpos pos))) (progn (end-of-line) (throw 'ret t)))))) ;; Key bindings (global-set-key [end] 'intelli-end) (global-set-key [home] 'intelli-home) - dhruva -- Proud FSF member: #1935 http://schemer.fateback.com/