From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andrey Tykhonov Newsgroups: gmane.emacs.help Subject: Re: Break code lines fluently Date: Thu, 13 Mar 2014 02:14:42 +0200 Message-ID: <878usft0nh.fsf@gmail.com> References: <87wqg0t1jz.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1394669743 3069 80.91.229.3 (13 Mar 2014 00:15:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Mar 2014 00:15:43 +0000 (UTC) To: Drew Adams , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Mar 13 01:15:50 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WNtJL-0003g4-9l for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Mar 2014 01:15:47 +0100 Original-Received: from localhost ([::1]:35824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNtJK-0005DL-OR for geh-help-gnu-emacs@m.gmane.org; Wed, 12 Mar 2014 20:15:46 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNtIp-000595-QK for help-gnu-emacs@gnu.org; Wed, 12 Mar 2014 20:15:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNtIi-00030O-Ku for help-gnu-emacs@gnu.org; Wed, 12 Mar 2014 20:15:15 -0400 Original-Received: from mail-ea0-x22f.google.com ([2a00:1450:4013:c01::22f]:56190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNtIi-0002zE-8c for help-gnu-emacs@gnu.org; Wed, 12 Mar 2014 20:15:08 -0400 Original-Received: by mail-ea0-f175.google.com with SMTP id d10so164338eaj.20 for ; Wed, 12 Mar 2014 17:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=9mvaj0jtug0ki8MLGbZ4ypW0QYwl3hACntyCQyamVkw=; b=Z1/2s77ETh5bceoG5HQvQMR6ZkHLP27T/VAFTEXUl6TQXIX0aOXfAwBrPCCVrHhweh idFeZF4yQV7KS9q4eKEgwGIVOQcmFVao77pGqXFcO3lCGaKxP6aXUequvtvIfP0VgBaO pk5XTvBubcNJHanZyjLwpTmae7Y4qV18mRWLpCvoFy1U+ZGoI2yeOwV/L9StPnArAk0c BXrL9XTFRsvZqh6Enp58H4pmY506FdyWHVpuqI+C/2CMbdhyG3/HAI7aVUvZsILPmj3f iFjz1+lPbvlwZV7G1zVyPsD24WlJxypDJB/ZcYtVlGfTRk5JC/N65JAz5p0wIIzi8wRK yw5A== X-Received: by 10.14.198.71 with SMTP id u47mr284636een.89.1394669707204; Wed, 12 Mar 2014 17:15:07 -0700 (PDT) Original-Received: from demi.gmail ([193.84.22.38]) by mx.google.com with ESMTPSA id f45sm1839924eeg.5.2014.03.12.17.15.05 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 12 Mar 2014 17:15:06 -0700 (PDT) In-Reply-To: (Drew Adams's message of "Wed, 12 Mar 2014 07:25:07 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22f X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96483 Archived-At: Drew Adams writes: >> (defun test () >> (let ((test t)) >> (if test >> (message "True") >> (mes|sage "False")))) >> Point is located in the middle of "message" function. And I would like to >> insert more code to the `let' form (after the `if'). > > Here is one approach: > > C-- 2 C-M-u RET > > C-M-u is `backward-up-list'. You give it a negative prefix arg to go > forward instead of backward. -2 means go forward and up past (-1) the > `message' sexp and then (-2) past the `if' sexp. RET then indents > (with recent Emacs dev snapshots - use C-j with older versions). > > If you don't want to count, just repeat C-- C-M-u until you get where > you want to go. > > You can also bind `up-list' to a key, and use that to do the same > thing as C-M-u with a negative arg. E.g. > > M-x global-set-key C-o RET up-list RET > > C-o C-o RET ; move up & forward 2 list levels, then newline & indent > > The real advantage of binding a key to `up-list' is that you can > just hold that key (C-o or whatever) down until you get where you > want (the same as you can do with `backward-up-list', C-M-u). > > Prefix key `C-M-' introduces Lisp stuff in Emacs-Lisp mode, including > commands that move over lists: e.g., C-M-u, C-M-d, C-M-n, C-M-p. And > commands that move over sexps, whether lists or not: C-M-f, C-M-b. > > Others will no doubt give you other ways, in particular that make use > of 3rd-party libraries. There are many ways to skin this cat. > > (If you use a mouse, you can of course also just click where you want > to insert the newline: direct access. That's sometimes easier or > quicker, since you can see the destination and you don't need to move > there incrementally or by counting list levels. But it does take one > hand off the keyboard.) Thank you for such detailed the answer! I learned something new. I didn't know about `up-list' command and most of the mentioned key bindings. The goal of my little package is to insert new line (based on context) to a Emacs Lisp code by means of very handy way (I believe so). I like approach used by this package because it allows: 1) do not pay additional attention (by looking at highlighted opened bracket) whether my cursor is located after the right closing bracket (so then I can hit C-j and input a code); after execution of `smart-return' command new line indents so it is a little bit easily to note by means of indentation level whether it is right place to input new code or not; 2) do not perform additional *navigation* through the code (within opened and closed brackets) but just insert new line from the current cursor position and to be ready to input new code immediately (by means of one `smart-return' command execution or several). 3) to have one shorthand key binding (for example H-RET, as I have) instead of different combinations of key bindings. For example: (setq gnus-gcc-mark-as-read t gnus-expert-user t gnus-suppress-duplicates t gnus-con|firm-mail-reply-to-news t gnus-ignored-newsgroups "" nnml-get-new-mail t gnus-add-to-list t) to append new SYM/VAL pairs to the `setq' form I need to C-o (`up-list'), then C-b and lastly C-j. (Or probably the best way to do that is to hit C-M-f as much as required and then C-j). But instead of such navigation and following C-j I would like to have one command which can just *put* cursor in the right place and will allow just to input SYM/VAL pair to the `setq' form. Is case of such `setq' and `smart-return' it is required to hit key binding only once. "one hit" instead of several hits (in such case and others) probably doesn't bring a huge advantage. But for me valuable advantage is to have one key binding instead of several (such as `forward-sexp', `up-line') for such trivial purpose as insert new line. (By the way, I just updated this package and removed surplus `undo' step. So mentioned example in the original message could be performed by means of just three command executions instead of five). Thank you! Andrey