From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: "Soft" indent with visual-line-mode? Date: Fri, 11 Sep 2009 14:58:53 +0200 Message-ID: <87ab11zlgy.fsf@escher.local.home> References: <8CAC7B1B-0C66-4D38-B474-1C4150419B22@stoo.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1252676904 17463 80.91.229.12 (11 Sep 2009 13:48:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 11 Sep 2009 13:48:24 +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 Sep 11 15:48:18 2009 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 1Mm6U6-0000ZY-2o for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Sep 2009 15:48:18 +0200 Original-Received: from localhost ([127.0.0.1]:59091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm6U5-0006kX-HU for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Sep 2009 09:48:17 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mm5in-0005GH-1s for help-gnu-emacs@gnu.org; Fri, 11 Sep 2009 08:59:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mm5ii-0005A2-Kl for help-gnu-emacs@gnu.org; Fri, 11 Sep 2009 08:59:24 -0400 Original-Received: from [199.232.76.173] (port=59859 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm5ii-00059n-6J for help-gnu-emacs@gnu.org; Fri, 11 Sep 2009 08:59:20 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:34558) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Mm5ig-0000Kn-MH for help-gnu-emacs@gnu.org; Fri, 11 Sep 2009 08:59:19 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1Mm5id-0001xg-Ra for help-gnu-emacs@gnu.org; Fri, 11 Sep 2009 14:59:15 +0200 Original-Received: from i59f543e9.versanet.de ([89.245.67.233]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Sep 2009 14:59:15 +0200 Original-Received: from stephen.berman by i59f543e9.versanet.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Sep 2009 14:59:15 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 61 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: i59f543e9.versanet.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:68049 Archived-At: 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)))))