From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: GianUberto.Lauri@eng.it (Gian Uberto Lauri) Newsgroups: gmane.emacs.help Subject: Re: detect if line has only white space? Date: Mon, 10 Nov 2003 19:39:51 +0100 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <16303.56183.397055.26656@mail.eng.it> References: <87r80gdse3.fsf@despammed.com> Reply-To: saint@eng.it 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 1068489763 21922 80.91.224.253 (10 Nov 2003 18:42:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 10 Nov 2003 18:42:43 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 10 19:42:39 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AJGzn-0001Sq-00 for ; Mon, 10 Nov 2003 19:42:39 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AJHx4-0000Fs-Ro for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Nov 2003 14:43:54 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AJHwW-0000F2-PE for help-gnu-emacs@gnu.org; Mon, 10 Nov 2003 14:43:20 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AJHvy-0008VF-Mj for help-gnu-emacs@gnu.org; Mon, 10 Nov 2003 14:43:17 -0500 Original-Received: from [62.101.90.2] (helo=mail.eng.it) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AJHuY-0008B7-3O for help-gnu-emacs@gnu.org; Mon, 10 Nov 2003 14:41:18 -0500 Original-Received: from paperoga (localhost [127.0.0.1]) by mail.eng.it (Postfix) with ESMTP id D929C1782C; Mon, 10 Nov 2003 19:39:51 +0100 (CET) Original-To: marc0 Original-Newsgroups: gnu.emacs.help In-Reply-To: <87r80gdse3.fsf@despammed.com> X-Mailer: VM 7.07 under Emacs 21.2.1 X-attribution: CC X-Home-Page: http://www.gest.unipd.it/~saint X-Zippy: This ASEXUAL PIG really BOILS my BLOOD... He's so..so.....URGENT!! X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 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 Xref: main.gmane.org gmane.emacs.help:14004 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14004 >>>>> "m" == marc0 writes: m> Miguel Frasson on 10 Nov 2003 18:42:56 +0100 writes: >> I would like to have a elisp function that detects if the current line >> contains only white space. Some idea? m> matching the current line content with the regexp ^[ ]*$ ? >> Aditionally, I would like to remove all space at the end of the >> lines at once (e-lisp code). How? m> M-x replace-regexp RET [ ]*$ RET RET ;; I have this little piece of code in my .emacs (i think it comes from this list!): (defun remove-trailing-blanks (&optional ask) "Removes useless blanks from a buffer. Removes trailing spaces and tabs from every line in the current buffer, and trailing newlines from the end of the buffer, apart from one. If ASK is non-nil, ask for confirmation." (if (and (not (zerop (buffer-size))) (char-equal (char-after (buffer-size)) ? ) (save-excursion (save-restriction (save-match-data (widen) (goto-char 0) (or (search-forward " " nil t) (search-forward " " nil t) (re-search-forward " \`" nil t))))) (if ask (y-or-n-p "Remove trailing spaces and newlines before saving? ") (message "Removing trailing spaces and newlines...") t)) (save-excursion (save-restriction (save-match-data (widen) (goto-char 0) (while (re-search-forward "[ ]+$" nil `move) (replace-match "")) (if (bolp) (progn (skip-chars-backward " ") (delete-region (1+ (point)) (point-max)))) ))))) ;; that can be hooked to several modes: ;;; Remove trailing blanks and newlines before saving a text buffer. (add-hook 'text-mode-hook 'install-remove-trailing-blanks-ask) (add-hook 'emacs-lisp-mode-hook 'install-remove-trailing-blanks) (add-hook 'c-mode-hook 'install-remove-trailing-blanks) (add-hook 'c++-mode-hook 'install-remove-trailing-blanks) (add-hook 'octave-mode-hook 'install-remove-trailing-blanks) (add-hook 'jde-mode-hook 'install-remove-trailing-blanks) (defun install-remove-trailing-blanks () (add-hook 'write-contents-hooks 'remove-trailing-blanks)) (defun install-remove-trailing-blanks-ask () (add-hook 'write-contents-hooks '(lambda () (remove-trailing-blanks t)))) /\ ___ /___/\__|_|\_|__|___Gian Uberto Lauri_____________________ //--\ | | \| | Integralista GNUslamico e fancazzista \/