help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optional Arguments


From: Arthur Miller
Subject: Re: Optional Arguments
Date: Mon, 07 Dec 2020 21:52:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> pietru@caramail.com writes:
>
>> Am getting an error with the following.
>>
>> (defun word-markers ()
>>    (let ((ma mb)) <--
>
> You bind `ma' to the value of `mb'.  That's not what you want.
Exactly; this is what I had in my scratch when I tested: I just didn't
copy everything in previous answer:

(defun word-markers ()
  (let (ma mb)
    (skip-chars-backward "[:alpha:]")
    (setq ma (point))
    (skip-chars-forward "[:alpha:]")
    (setq mb (point))
    (cons ma mb)))

(defun test ()
   (interactive)
   (let ((deactivate-mark nil)
         bounds ma mb)
     (if (use-region-p)
         (setq ma (region-beginning) mb (region-end))
       (save-excursion
         (setq bounds (word-markers))
         (setq ma (car bounds))
         (setq mb (cdr bounds))))
   (message "Bounds: %s" (pp bounds))
   (message "Region: [%s %s]" ma mb)
   (message "Region-string: [%s]" (buffer-substring-no-properties ma mb))))

(test)

Tou should drop one parenthesis around ma and mb in your let
expression. That will declare two variables and initialize them to nil both.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]