From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: yank without indentation? Date: Thu, 5 Jun 2014 16:29:25 -0700 (PDT) Message-ID: References: <87oay7v179.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1402011008 27059 80.91.229.3 (5 Jun 2014 23:30:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Jun 2014 23:30:08 +0000 (UTC) Cc: help-gnu-emacs To: Jacob Gerlach , Eric Abrahamsen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 06 01:30:01 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 1Wsh6f-0004LI-2d for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Jun 2014 01:30:01 +0200 Original-Received: from localhost ([::1]:44244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsh6e-00011a-Cn for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jun 2014 19:30:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsh6L-0000mJ-27 for help-gnu-emacs@gnu.org; Thu, 05 Jun 2014 19:29:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wsh6C-0006nZ-7D for help-gnu-emacs@gnu.org; Thu, 05 Jun 2014 19:29:41 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:42811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wsh6C-0006nR-04 for help-gnu-emacs@gnu.org; Thu, 05 Jun 2014 19:29:32 -0400 Original-Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s55NTS7Y000381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 5 Jun 2014 23:29:28 GMT Original-Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id s55NTQEh000056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 5 Jun 2014 23:29:27 GMT Original-Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userz7022.oracle.com (8.14.5+Sun/8.14.4) with ESMTP id s55NTPFH029993; Thu, 5 Jun 2014 23:29:26 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6691.5000 (x86)] X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 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:98045 Archived-At: > Has anyone come up with a yank-without-indentation routine? Why am I > always killing multi-line text with enormous left-hand whitespace, and > wanting to yank it without that whitespace in place? Has anyone dealt > with this? This should do pretty much what you want. (defun yank-sans-indent (&optional arg) "Like `yank', but remove indentation." (interactive "*P") (setq yank-window-start (window-start) this-command t) (push-mark (point)) (insert-for-yank (string-trim (current-kill (cond ((listp arg) 0) ((eq arg '-) -2) (t (1- arg)))))) (when (consp arg) (goto-char (prog1 (mark t) (set-marker (mark-marker) (point) (current-buffer))))) (when (eq this-command t) (setq this-command 'yank-sans-indent)) nil) (defun string-trim (string) "Trim SPC and TAB chars from ends of STRING and each of its eols." (let* ((start (progn (string-match "\\`[ \t]*" string) (match-end 0))) (end (progn (string-match "[ \t]*\\'" string start) (match-beginning 0))) (trimmed (substring string start end))) (replace-regexp-in-string "\\(\n\\)[ \t]+" "\\1" trimmed))) (global-set-key "\C-y" 'yank-sans-indent) (You can also bind `M-y' to a command that is `yank-pop' but with references to `yank' replaced by `yank-sans-indent'.) [If you want the string that is placed on the `kill-ring' to be the complete selected text, instead of that text trimmed to remove indentation, then you can use an alternative approach of placing a `yank-handler' property on the first character, and define a yank handler that trims the indenting whitespace at the time of insertion.]