From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Stewart Newsgroups: gmane.emacs.help Subject: Re: "Soft" indent with visual-line-mode? Date: Fri, 09 Dec 2011 15:25:22 -0500 Organization: Stoo Research Message-ID: <4EE26EB2.3030401@stoo.org> References: <8CAC7B1B-0C66-4D38-B474-1C4150419B22@stoo.org> <87ab11zlgy.fsf@escher.local.home> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1323462382 9023 80.91.229.12 (9 Dec 2011 20:26:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 9 Dec 2011 20:26:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 09 21:26:18 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RZ71O-0001ow-5m for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Dec 2011 21:26:18 +0100 Original-Received: from localhost ([::1]:45465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZ71N-0004jx-I8 for geh-help-gnu-emacs@m.gmane.org; Fri, 09 Dec 2011 15:26:17 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:39806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZ70a-0004er-IL for help-gnu-emacs@gnu.org; Fri, 09 Dec 2011 15:25:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RZ70Z-0005IQ-FZ for help-gnu-emacs@gnu.org; Fri, 09 Dec 2011 15:25:28 -0500 Original-Received: from munch.stoo.org ([208.87.198.215]:52572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RZ70Z-0005ID-2j for help-gnu-emacs@gnu.org; Fri, 09 Dec 2011 15:25:27 -0500 Original-Received: from [10.1.1.88] (static-71-190-247-30.nycmny.fios.verizon.net [71.190.247.30]) by munch.stoo.org (Stoo Research Mail Services) with ESMTPSA id 380EC3F5B for ; Fri, 9 Dec 2011 15:25:23 -0500 (EST) User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20110417 Lightning/1.0b2 Thunderbird/3.1.4 In-Reply-To: <87ab11zlgy.fsf@escher.local.home> X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 208.87.198.215 X-Mailman-Approved-At: Fri, 09 Dec 2011 15:26:12 -0500 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:83172 Archived-At: On 09/11/09 08:58 AM, Stephen Berman wrote: > On Wed, 9 Sep 2009 13:53:58 -0400 Tim Stewart wrote: > >> Hello Emacs Help, >> >> I like the idea of using longlines-mode or visual-line-mode to spend less time >> formatting code as I write. However, it is not useful to me when the wrapped >> lines start in the first column and break up the flow of the code. >> >> As an example, this is what I get now with a line that is indented 4 spaces. >> This is all one line, wrapped by the editor for me: >> >> This is a test of the emergency broadcast system. This is only a test. In >> the event of a real emergency, your head would have exploded. >> >> And this is what I want: >> >> This is a test of the emergency broadcast system. This is only a test. In >> the event of a real emergency, your head would have exploded. >> >> I've heard this referred to as a "soft" indent. I believe that Visual >> SlickEdit 9 and Kate both support this feature if you'd like other examples. >> >> Does anyone know of a feature or add-on for Emacs that can accomplish this? >> I've scoured the 'Tubes and can't find anything. > > The following code might do what you want, though it might need some > tweaking. (To use it, evaluate it and call the minor mode manually or > add it to appropriate mode hooks.) > > Steve Berman > > (defun srb-adaptive-indent (beg end) > "Indent the region between BEG and END with adaptive filling." > (goto-char beg) > (while > (let ((lbp (line-beginning-position)) > (lep (line-end-position))) > (put-text-property lbp lep 'wrap-prefix (fill-context-prefix lbp lep)) > (search-forward "\n" end t)))) > > (define-minor-mode srb-adaptive-wrap-mode > "Wrap the buffer text with adaptive filling." > :lighter "" > (save-excursion > (save-restriction > (widen) > (let ((buffer-undo-list t) > (inhibit-read-only t) > (mod (buffer-modified-p))) > (if srb-adaptive-wrap-mode > (progn > (setq word-wrap t) > (unless (member '(continuation) fringe-indicator-alist) > (push '(continuation) fringe-indicator-alist)) > (jit-lock-register 'srb-adaptive-indent)) > (jit-lock-unregister 'srb-adaptive-indent) > (remove-text-properties (point-min) (point-max) '(wrap-prefix pref)) > (setq fringe-indicator-alist > (delete '(continuation) fringe-indicator-alist)) > (setq word-wrap nil)) > (restore-buffer-modified-p mod))))) It took me quite a while to try this. Thank you Steve, it works quite well! It was a little odd in Emacs Lisp mode, but seems to work great in more block-oriented code like Python, C, Perl, etc. I also added the following to make it easy to enable globally and I tucked it away in my load-path as srb-adaptive-wrap-mode.el: (defun turn-on-srb-adaptive-wrap-mode () (srb-adaptive-wrap-mode 1)) (define-globalized-minor-mode global-srb-adaptive-wrap-mode srb-adaptive-wrap-mode turn-on-srb-adaptive-wrap-mode :lighter "") (provide 'srb-adaptive-wrap-mode) I also turn on the gutter arrows to make it more obvious what's happening: ; Let's show the fringe indicators when in visual-line-mode (setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow)) Thanks again! -TimS -- Tim Stewart Stoo Research +1 404 993 6492