all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Anders Dalskov" <anderspkd@fastmail.com>
To: tomas@tuxteam.de, pietru@caramail.com
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Optional Arguments
Date: Mon, 07 Dec 2020 14:35:51 +0100	[thread overview]
Message-ID: <efe744d4-962d-4370-abb5-00ee43983e0a@www.fastmail.com> (raw)
In-Reply-To: <20201207130630.GA10719@tuxteam.de>

Doesn't `(bounds-of-thing-at-point 'word)` accomplish what you want?

On Mon, Dec 7, 2020, at 14:06, tomas@tuxteam.de wrote:
> On Mon, Dec 07, 2020 at 01:37:34PM +0100, pietru@caramail.com wrote:
> > 
> > 
> > > Sent: Monday, December 07, 2020 at 9:16 AM
> > > From: "Alexis Roda" <alexis.roda.villalonga@gmail.com>
> > > To: pietru@caramail.com
> > > Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> > > Subject: Re: Optional Arguments
> > >
> > > Hi,
> > > 
> > > Not sure what your question is.
> > 
> > It is bit confusing.
> > 
> > I want to use typh-word-markers to compute ma and mb so I can use the
> > two values in another function.  Had put (interactive) in my effort to
> > test it, but created problems as you say.  The function would be called
> > when cursor is on a word, so that I get the word "beg" and "end".
> > 
> > (defun typh-word-markers (ma mb)
> 
> [...]
> 
> As Alexis already said, the parameters in your function aren't probably
> doing what you think they do. Consider:
> 
>   (setq ma 15)
>   (setq mb 26)
>   
>   (defun foo (ma mb)
>     (setq ma 5)
>     (setq mb 6)
>     (message "ma: %d mb: %d" ma mb))
>   
>   (foo ma mb)
> 
> => "ma: 5 mb: 6"
> 
>   (message "ma: %d mb: %d" ma mb)
> 
> => "ma: 15 mb: 26"
> 
> I suspect you are passing the parameters to get their values
> "outside" the function. I can only guess that, because you don't
> show any context (take this into account to help others help
> you :)
> 
> But this won't work, because the (setq ...) whithin the function
> doesn't "see" the variables outside, but creates variables inside,
> initialized to whatever /values/ you pass to the function at call
> time.
> 
> In other words: what would you expect your function `typh-word-markers'
> do do if you call it like so:
> 
>   (typh-word-markers 15 16)
> 
> ...would you expect it to change the number 15 to whatever the word's
> beginning position is? You would mess up maths with that :)
> 
> Cheers
>  - t
> 
> Attachments:
> * signature.asc

-- 
Anders



  reply	other threads:[~2020-12-07 13:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07  3:17 Optional Arguments pietru
2020-12-07  8:16 ` Alexis Roda
2020-12-07 12:37   ` pietru
2020-12-07 13:06     ` tomas
2020-12-07 13:35       ` Anders Dalskov [this message]
2020-12-07 14:24       ` pietru
2020-12-07 15:38         ` tomas
2020-12-07 18:13           ` pietru
2020-12-07 19:01             ` Arthur Miller
2020-12-07 19:42               ` pietru
2020-12-07 19:54                 ` Michael Heerdegen
2020-12-07 20:21                   ` pietru
2020-12-07 20:52                   ` Arthur Miller
2020-12-07 21:21                     ` pietru
2020-12-07 19:51             ` Alexis Roda
2020-12-07 15:06       ` pietru
2020-12-07 15:51         ` tomas
2020-12-07 17:51           ` pietru
2020-12-07 18:33             ` Arthur Miller
2020-12-07 18:49               ` pietru
2020-12-07 20:13             ` Stefan Monnier
2020-12-07 20:25               ` pietru
2020-12-07 20:39                 ` Christopher Dimech

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=efe744d4-962d-4370-abb5-00ee43983e0a@www.fastmail.com \
    --to=anderspkd@fastmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pietru@caramail.com \
    --cc=tomas@tuxteam.de \
    /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.