[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 20:01:59 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
pietru@caramail.com writes:
> I'm having a go at returning the two values from a function
>
> (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 $mu (car bounds))
> (setq $mv (car bounds)) ))
>
> (message "Bounds: %s" $bounds)
> (message "Region: [%s, %s]" $ma $mb) ))
>
> But something's not right.
You have probably made a typo when you are setq-ing 'mu' and 'mv'
> (setq $mu (car bounds)) <-- introducing new variable in global scope: $mu
> (setq $mv (car bounds)) <-- same here: $mv
> (message "Region: [%s, %s]" $ma $mb) <-- potentially nil vars $ma and $mb
You probably want somthing like this:
(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 ma mb))))
- Optional Arguments, pietru, 2020/12/06
- Re: Optional Arguments, Alexis Roda, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, tomas, 2020/12/07
- Re: Optional Arguments, Anders Dalskov, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, tomas, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments,
Arthur Miller <=
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Michael Heerdegen, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Alexis Roda, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, tomas, 2020/12/07
- Re: Optional Arguments, pietru, 2020/12/07
- Re: Optional Arguments, Arthur Miller, 2020/12/07