From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: forward-word - optional argument Date: 12 Aug 2003 19:52:21 +0300 Organization: JURTA Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <87adaeom2i.fsf@mail.jurta.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1060707544 20472 80.91.224.253 (12 Aug 2003 16:59:04 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 12 Aug 2003 16:59:04 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Tue Aug 12 18:59:03 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19mcUB-00007V-00 for ; Tue, 12 Aug 2003 18:59:03 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19mcbx-0006zV-00 for ; Tue, 12 Aug 2003 19:07:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mcSi-0001li-0M for emacs-devel@quimby.gnus.org; Tue, 12 Aug 2003 12:57:32 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19mcSc-0001jg-MB for emacs-devel@gnu.org; Tue, 12 Aug 2003 12:57:26 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19mcS5-0000vi-Uk for emacs-devel@gnu.org; Tue, 12 Aug 2003 12:57:25 -0400 Original-Received: from [64.246.52.22] (helo=ns5.tangramltd.com) by monty-python.gnu.org with esmtp (Exim 4.20) id 19mcS4-0000sc-1k for emacs-devel@gnu.org; Tue, 12 Aug 2003 12:56:52 -0400 Original-Received: from 80-235-41-215-dsl.mus.estpak.ee ([80.235.41.215] helo=mail.jurta.org) by ns5.tangramltd.com with esmtp (Exim 4.20) id 19mcRw-0000rq-RO for emacs-devel@gnu.org; Tue, 12 Aug 2003 19:56:45 +0300 Original-To: emacs-devel@gnu.org User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (gnu/linux) Original-Lines: 199 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ns5.tangramltd.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - jurta.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:15906 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15906 While using the compare-windows with synchronization I recently posted here, I found the following problem: if `compare-windows-sync' is set to function `forward-word', then calling it by `funcall' without arguments gives the error about wrong number of arguments. It's because the argument of `forward-word' is not optional, whereas most other forward-related functions have their argument optional: (forward-char &optional N) (forward-line &optional N) (forward-list &optional ARG) (forward-page &optional COUNT) (forward-paragraph &optional ARG) (forward-sentence &optional ARG) (forward-sexp &optional ARG) The following patch makes the argument of `forward-word' and `backward-word' optional. By default, it uses the value 1. BTW, the inconvenience caused by the lack of optional argument of `forward-word' can be traced in ChangeLog files back to 1985-08-06! I hope this patch finally fixes it. emacs/src/ChangeLog: 2003-08-12 Juri Linkov * syntax.c (Fforward_word): Argument changed to optional. Set default value to 1. Index: emacs/src/syntax.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/syntax.c,v retrieving revision 1.166 diff -c -r1.166 syntax.c *** emacs/src/syntax.c 17 May 2003 12:50:24 -0000 1.166 --- emacs/src/syntax.c 12 Aug 2003 15:04:59 -0000 *************** *** 1277,1297 **** return from; } ! DEFUN ("forward-word", Fforward_word, Sforward_word, 1, 1, "p", doc: /* Move point forward ARG words (backward if ARG is negative). Normally returns t. If an edge of the buffer or a field boundary is reached, point is left there and the function returns nil. Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */) ! (count) ! Lisp_Object count; { int orig_val, val; - CHECK_NUMBER (count); ! val = orig_val = scan_words (PT, XINT (count)); if (! orig_val) ! val = XINT (count) > 0 ? ZV : BEGV; /* Avoid jumping out of an input field. */ val = XFASTINT (Fconstrain_to_field (make_number (val), make_number (PT), --- 1277,1301 ---- return from; } ! DEFUN ("forward-word", Fforward_word, Sforward_word, 0, 1, "p", doc: /* Move point forward ARG words (backward if ARG is negative). Normally returns t. If an edge of the buffer or a field boundary is reached, point is left there and the function returns nil. Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */) ! (arg) ! Lisp_Object arg; { int orig_val, val; ! if (NILP (arg)) ! XSETFASTINT (arg, 1); ! else ! CHECK_NUMBER (arg); ! ! val = orig_val = scan_words (PT, XINT (arg)); if (! orig_val) ! val = XINT (arg) > 0 ? ZV : BEGV; /* Avoid jumping out of an input field. */ val = XFASTINT (Fconstrain_to_field (make_number (val), make_number (PT), =================================================================== emacs/lisp/ChangeLog: 2003-08-12 Juri Linkov * simple.el (backward-word, forward-to-indentation) (backward-to-indentation): Argument changed to optional. (next-line, previous-line): Use `or' instead of `unless'. Index: emacs/lisp/simple.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v retrieving revision 1.616 diff -c -r1.616 simple.el *** emacs/lisp/simple.el 25 Jul 2003 12:18:04 -0000 1.616 --- emacs/lisp/simple.el 12 Aug 2003 15:02:03 -0000 *************** *** 352,366 **** (insert-and-inherit char) (setq arg (1- arg))))) ! (defun forward-to-indentation (arg) "Move forward ARG lines and position at first nonblank character." (interactive "p") (forward-line arg) (skip-chars-forward " \t")) ! (defun backward-to-indentation (arg) "Move backward ARG lines and position at first nonblank character." (interactive "p") (forward-line (- arg)) (skip-chars-forward " \t")) --- 352,368 ---- (insert-and-inherit char) (setq arg (1- arg))))) ! (defun forward-to-indentation (&optional arg) "Move forward ARG lines and position at first nonblank character." (interactive "p") + (or arg (setq arg 1)) (forward-line arg) (skip-chars-forward " \t")) ! (defun backward-to-indentation (&optional arg) "Move backward ARG lines and position at first nonblank character." (interactive "p") + (or arg (setq arg 1)) (forward-line (- arg)) (skip-chars-forward " \t")) *************** *** 2697,2703 **** using `forward-line' instead. It is usually easier to use and more reliable (no dependence on goal column, etc.)." (interactive "p") ! (unless arg (setq arg 1)) (if (and next-line-add-newlines (= arg 1)) (if (save-excursion (end-of-line) (eobp)) ;; When adding a newline, don't expand an abbrev. --- 2699,2705 ---- using `forward-line' instead. It is usually easier to use and more reliable (no dependence on goal column, etc.)." (interactive "p") ! (or arg (setq arg 1)) (if (and next-line-add-newlines (= arg 1)) (if (save-excursion (end-of-line) (eobp)) ;; When adding a newline, don't expand an abbrev. *************** *** 2729,2735 **** `forward-line' with a negative argument instead. It is usually easier to use and more reliable (no dependence on goal column, etc.)." (interactive "p") ! (unless arg (setq arg 1)) (if (interactive-p) (condition-case nil (line-move (- arg)) --- 2731,2737 ---- `forward-line' with a negative argument instead. It is usually easier to use and more reliable (no dependence on goal column, etc.)." (interactive "p") ! (or arg (setq arg 1)) (if (interactive-p) (condition-case nil (line-move (- arg)) *************** *** 3109,3118 **** (goto-char (car pos1)) (insert word2)))) ! (defun backward-word (arg) "Move backward until encountering the beginning of a word. With argument, do this that many times." (interactive "p") (forward-word (- arg))) (defun mark-word (arg) --- 3111,3121 ---- (goto-char (car pos1)) (insert word2)))) ! (defun backward-word (&optional arg) "Move backward until encountering the beginning of a word. With argument, do this that many times." (interactive "p") + (or arg (setq arg 1)) (forward-word (- arg))) (defun mark-word (arg) =================================================================== -- http://www.jurta.org/emacs/