all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Define interactive function with arguments
@ 2020-10-08 23:15 Christopher Dimech
  2020-10-08 23:41 ` Stefan Monnier
  2020-10-08 23:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 11+ messages in thread
From: Christopher Dimech @ 2020-10-08 23:15 UTC (permalink / raw)
  To: Help Gnu Emacs

I want to call a function that takes a numeric argument
to I can shift paragraphs.

( defun Transpose-Paragraphs-Arg (arg)
    "Transfer paragraph backward"
    (interactive)
    (transpose-paragraphs arg)
)

I have been using "M-x Transpose-Paragraphs-Arg"

But then, how does one pass the value of the argument
to the function.

Regards
Christopher




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-08 23:15 Define interactive function with arguments Christopher Dimech
@ 2020-10-08 23:41 ` Stefan Monnier
  2020-10-08 23:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2020-10-08 23:41 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun Transpose-Paragraphs-Arg (arg)
>     "Transfer paragraph backward"
>     (interactive)
>     (transpose-paragraphs arg))
>
> I have been using "M-x Transpose-Paragraphs-Arg"

I doubt you have with the code above, because it will signal an error.
You need to provide something to `interactive` in order to build the
`arg` argument.


        Stefan




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-08 23:15 Define interactive function with arguments Christopher Dimech
  2020-10-08 23:41 ` Stefan Monnier
@ 2020-10-08 23:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-10-09  6:38   ` Christopher Dimech
  1 sibling, 1 reply; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-10-08 23:47 UTC (permalink / raw)
  To: help-gnu-emacs

Christopher Dimech wrote:

> I want to call a function that takes a numeric
> argument to I can shift paragraphs.
>
> ( defun Transpose-Paragraphs-Arg (arg)
>     "Transfer paragraph backward"
>     (interactive)
>     (transpose-paragraphs arg)
> )
>
> I have been using "M-x Transpose-Paragraphs-Arg"
>
> But then, how does one pass the value of the
> argument to the function.

C-u X M-x transpose-paragraphs RET

where X marks the spot!

Use without an explicit number also works,

  just C-u - 4
  then C-u C-u - 16
  and so on

Also negative values are possible, e.g.

  C-u -1 M-x transpose-paragraphs RET

Also works with shortcuts.

See

  C-h f universal-argument RET

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-08 23:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-10-09  6:38   ` Christopher Dimech
  2020-10-09  7:18     ` Joost Kremers
  0 siblings, 1 reply; 11+ messages in thread
From: Christopher Dimech @ 2020-10-09  6:38 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs

Is the following code the way to write user defined functions
with arguments?

( defun Transpose-Paragraphs-Arg (arg)
    "Transfer paragraph backward"
    (interactive)
    (transpose-paragraphs arg)
)

Regards
C*


> Sent: Friday, October 09, 2020 at 1:47 AM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Define interactive function with arguments
>
> Christopher Dimech wrote:
>
> > I want to call a function that takes a numeric
> > argument to I can shift paragraphs.
> >
> > ( defun Transpose-Paragraphs-Arg (arg)
> >     "Transfer paragraph backward"
> >     (interactive)
> >     (transpose-paragraphs arg)
> > )
> >
> > I have been using "M-x Transpose-Paragraphs-Arg"
> >
> > But then, how does one pass the value of the
> > argument to the function.
>
> C-u X M-x transpose-paragraphs RET
>
> where X marks the spot!
>
> Use without an explicit number also works,
>
>   just C-u - 4
>   then C-u C-u - 16
>   and so on
>
> Also negative values are possible, e.g.
>
>   C-u -1 M-x transpose-paragraphs RET
>
> Also works with shortcuts.
>
> See
>
>   C-h f universal-argument RET
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09  6:38   ` Christopher Dimech
@ 2020-10-09  7:18     ` Joost Kremers
  2020-10-09  8:57       ` Christopher Dimech
  0 siblings, 1 reply; 11+ messages in thread
From: Joost Kremers @ 2020-10-09  7:18 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: help-gnu-emacs, moasenwood


On Fri, Oct 09 2020, Christopher Dimech wrote:
> Is the following code the way to write user defined functions
> with arguments?
>
> ( defun Transpose-Paragraphs-Arg (arg)
>     "Transfer paragraph backward"
>     (interactive)
>     (transpose-paragraphs arg)
> )

With all due respect, you should really read the Emacs Lisp Intro, it answers
this and all (or at least most) other questions you've posted.

In Emacs, press `C-h i m Emacs Lisp Intro RET` and start reading. Or, if you
prefer online:

https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html

Once you've mastered the introduction, you'll find more info in the Elisp
manual:

C-h i m Elisp RET

or

https://www.gnu.org/software/emacs/manual/html_node/elisp/

HTH

-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09  7:18     ` Joost Kremers
@ 2020-10-09  8:57       ` Christopher Dimech
  2020-10-09  9:22         ` Joost Kremers
  2020-10-09 14:01         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 11+ messages in thread
From: Christopher Dimech @ 2020-10-09  8:57 UTC (permalink / raw)
  To: Joost Kremers; +Cc: help-gnu-emacs, moasenwood

Your comment simply means, look at the manual and look at the code
and don't bother me.  Nobody forced you to reply, and if people do
not want to advise, they can simply disregard me.  Have heard such
talk all the time, especially in industry.

Regards
Christopher

--------------------
Christopher Dimech
General Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy




> Sent: Friday, October 09, 2020 at 9:18 AM
> From: "Joost Kremers" <joostkremers@fastmail.fm>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: moasenwood@zoho.eu, help-gnu-emacs@gnu.org
> Subject: Re: Define interactive function with arguments
>
>
> On Fri, Oct 09 2020, Christopher Dimech wrote:
> > Is the following code the way to write user defined functions
> > with arguments?
> >
> > ( defun Transpose-Paragraphs-Arg (arg)
> >     "Transfer paragraph backward"
> >     (interactive)
> >     (transpose-paragraphs arg)
> > )
>
> With all due respect, you should really read the Emacs Lisp Intro, it answers
> this and all (or at least most) other questions you've posted.
>
> In Emacs, press `C-h i m Emacs Lisp Intro RET` and start reading. Or, if you
> prefer online:
>
> https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html
>
> Once you've mastered the introduction, you'll find more info in the Elisp
> manual:
>
> C-h i m Elisp RET
>
> or
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/
>
> HTH
>
> --
> Joost Kremers
> Life has its moments
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09  8:57       ` Christopher Dimech
@ 2020-10-09  9:22         ` Joost Kremers
  2020-10-09  9:52           ` Christopher Dimech
  2020-10-09 14:01         ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 11+ messages in thread
From: Joost Kremers @ 2020-10-09  9:22 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: help-gnu-emacs, moasenwood


On Fri, Oct 09 2020, Christopher Dimech wrote:
> Your comment simply means, look at the manual and look at the 
> code
> and don't bother me.  Nobody forced you to reply, and if people 
> do
> not want to advise, they can simply disregard me.  Have heard 
> such
> talk all the time, especially in industry.

I'm truly sorry if it came across wrong, but I didn't mean my 
comment that way. It was meant in a "help someone help themself" 
kind of way. The Emacs Lisp Intro is a very helpful resource (I 
think) and I didn't see anyone point it out yet. (Though I may of course have 
missed it, in which case I apologise.)

In the spirit of helpfulness, these two sections of the Elisp 
Intro answer your specific question:

https://www.gnu.org/software/emacs/manual/html_node/eintr/Interactive.html#Interactive

and:

https://www.gnu.org/software/emacs/manual/html_node/eintr/Interactive-Options.html#Interactive-Options


-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09  9:22         ` Joost Kremers
@ 2020-10-09  9:52           ` Christopher Dimech
  2020-10-09 14:03             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: Christopher Dimech @ 2020-10-09  9:52 UTC (permalink / raw)
  To: Joost Kremers; +Cc: help-gnu-emacs, moasenwood

Joost, apology accepted. It is at times beneficial to assume others
know something you don't. Reading the manuals was pointed out and have
checked them, but they are one tough cookie unless one already knows a
decent amount and has used it to do real work.  The most useful thing I
found was describe-function.

I plan to write an abbreviated manual for this stuff, as I found it very easy
to get impatient reading so much material before you can start getting things
done.  Naturally the code I am doing is going to be released, so that new users
can easily set up their new Gnu Machine with some handy keybindings that new users
can find useful, quick to understand, and by referring to the code and the abbreviated
manual, quickly learn the basics of Emacs Lisp for their own work.

Regards
Christopher



---------------------
Christopher Dimech
Chief Administrator - Naiad Informatics - GNU Project (Geocomputation)
- Geophysical Simulation
- Geological Subsurface Mapping
- Disaster Preparedness and Mitigation
- Natural Resource Exploration and Production
- Free Software Advocacy


> Sent: Friday, October 09, 2020 at 11:22 AM
> From: "Joost Kremers" <joostkremers@fastmail.fm>
> To: "Christopher Dimech" <dimech@gmx.com>
> Cc: moasenwood@zoho.eu, help-gnu-emacs@gnu.org
> Subject: Re: Define interactive function with arguments
>
>
> On Fri, Oct 09 2020, Christopher Dimech wrote:
> > Your comment simply means, look at the manual and look at the
> > code
> > and don't bother me.  Nobody forced you to reply, and if people
> > do
> > not want to advise, they can simply disregard me.  Have heard
> > such
> > talk all the time, especially in industry.
>
> I'm truly sorry if it came across wrong, but I didn't mean my
> comment that way. It was meant in a "help someone help themself"
> kind of way. The Emacs Lisp Intro is a very helpful resource (I
> think) and I didn't see anyone point it out yet. (Though I may of course have
> missed it, in which case I apologise.)
>
> In the spirit of helpfulness, these two sections of the Elisp
> Intro answer your specific question:
>
> https://www.gnu.org/software/emacs/manual/html_node/eintr/Interactive.html#Interactive
>
> and:
>
> https://www.gnu.org/software/emacs/manual/html_node/eintr/Interactive-Options.html#Interactive-Options
>
>
> --
> Joost Kremers
> Life has its moments
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09  8:57       ` Christopher Dimech
  2020-10-09  9:22         ` Joost Kremers
@ 2020-10-09 14:01         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-10-09 14:24           ` Christopher Dimech
  1 sibling, 1 reply; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-10-09 14:01 UTC (permalink / raw)
  To: help-gnu-emacs

Christopher Dimech wrote:

> Your comment simply means, look at the manual [...]

If you don't want to look at the manual, how about:

  1. think

  2. byte compile and read the warnings and errors

  3. do C-h f FUN RET and C-h v VAR RET for
     everything in your ... code

  4. OK?

And yes, TBH do us all a favor and drop that style :$
use proper whitespace, case, names that makes sense,
indentation, comments, and all that, before this
turns into an embarrassment to the sport :(

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09  9:52           ` Christopher Dimech
@ 2020-10-09 14:03             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 11+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-10-09 14:03 UTC (permalink / raw)
  To: help-gnu-emacs

Christopher Dimech wrote:

> I plan to write an abbreviated manual for this
> stuff [...]

...

:)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Define interactive function with arguments
  2020-10-09 14:01         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-10-09 14:24           ` Christopher Dimech
  0 siblings, 0 replies; 11+ messages in thread
From: Christopher Dimech @ 2020-10-09 14:24 UTC (permalink / raw)
  To: moasenwood; +Cc: help-gnu-emacs

Have looked at what I send and have used indentation, whitespace,
etc but during the sending operation it is scrambling the whole code.
Will look into it so it will show right.

> Sent: Friday, October 09, 2020 at 4:01 PM
> From: "Emanuel Berg via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Define interactive function with arguments
>
> Christopher Dimech wrote:
>
> > Your comment simply means, look at the manual [...]
>
> If you don't want to look at the manual, how about:
>
>   1. think
>
>   2. byte compile and read the warnings and errors
>
>   3. do C-h f FUN RET and C-h v VAR RET for
>      everything in your ... code
>
>   4. OK?
>
> And yes, TBH do us all a favor and drop that style :$
> use proper whitespace, case, names that makes sense,
> indentation, comments, and all that, before this
> turns into an embarrassment to the sport :(
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
> https://dataswamp.org/~incal
>
>
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-10-09 14:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-08 23:15 Define interactive function with arguments Christopher Dimech
2020-10-08 23:41 ` Stefan Monnier
2020-10-08 23:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-09  6:38   ` Christopher Dimech
2020-10-09  7:18     ` Joost Kremers
2020-10-09  8:57       ` Christopher Dimech
2020-10-09  9:22         ` Joost Kremers
2020-10-09  9:52           ` Christopher Dimech
2020-10-09 14:03             ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-09 14:01         ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-10-09 14:24           ` Christopher Dimech

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.