all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Subject: forward-word - optional argument
Date: 12 Aug 2003 19:52:21 +0300	[thread overview]
Message-ID: <87adaeom2i.fsf@mail.jurta.org> (raw)

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  <juri@jurta.org>

	* 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  <juri@jurta.org>

	* 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))))
  \f
! (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))))
  \f
! (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/

                 reply	other threads:[~2003-08-12 16:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87adaeom2i.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.