all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* hook and interactive with parameter
@ 2018-02-12 10:03 Lajos Bodnar
  0 siblings, 0 replies; 12+ messages in thread
From: Lajos Bodnar @ 2018-02-12 10:03 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,
I'm new in emacs scripting but I would like to do that:
- I open a file after the file hook run I would like to run a function.
- I can do this without parameter but if I would like to use this function
with getting input from prompt. It will throw an error.

How can I do it what is the correct way to run this function?

(add-hook '...-hook 'my-function)

(defun my-function (param1)
   (interactive "sParam1: ")
   ....))

regards
Lajos


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

* Re: hook and interactive with parameter
       [not found] <mailman.8968.1518443498.27995.help-gnu-emacs@gnu.org>
@ 2018-02-12 15:28 ` Emanuel Berg
  2018-02-12 15:43   ` Lajos Bodnar
       [not found]   ` <mailman.8974.1518450193.27995.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Emanuel Berg @ 2018-02-12 15:28 UTC (permalink / raw)
  To: help-gnu-emacs

Lajos Bodnar wrote:

> Hi, I'm new in emacs scripting but I would
> like to do that: - I open a file after the
> file hook run I would like to run a function.
> - I can do this without parameter but if
> I would like to use this function with
> getting input from prompt. It will throw
> an error.

Can you rephrase this not in terms of the
un-implemented implementation but in terms of
what will happen, where, when, and why?

Might be easier to understand that way and
quite possible there is a better way than
messing with hooks - often there is.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: hook and interactive with parameter
  2018-02-12 15:28 ` Emanuel Berg
@ 2018-02-12 15:43   ` Lajos Bodnar
  2018-02-12 16:15     ` tomas
       [not found]     ` <mailman.8981.1518452114.27995.help-gnu-emacs@gnu.org>
       [not found]   ` <mailman.8974.1518450193.27995.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 12+ messages in thread
From: Lajos Bodnar @ 2018-02-12 15:43 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

Thanks for your advice.
I would like to write a function which run up if I open a haskell file.
This function will ask a question automaticaly about that i would like to
run the intero-mode or not.

regards
Lajos



On Mon, Feb 12, 2018 at 4:28 PM, Emanuel Berg <moasen@zoho.com> wrote:

> Lajos Bodnar wrote:
>
> > Hi, I'm new in emacs scripting but I would
> > like to do that: - I open a file after the
> > file hook run I would like to run a function.
> > - I can do this without parameter but if
> > I would like to use this function with
> > getting input from prompt. It will throw
> > an error.
>
> Can you rephrase this not in terms of the
> un-implemented implementation but in terms of
> what will happen, where, when, and why?
>
> Might be easier to understand that way and
> quite possible there is a better way than
> messing with hooks - often there is.
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
>


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

* Re: hook and interactive with parameter
  2018-02-12 15:43   ` Lajos Bodnar
@ 2018-02-12 16:15     ` tomas
       [not found]     ` <mailman.8981.1518452114.27995.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 12+ messages in thread
From: tomas @ 2018-02-12 16:15 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Feb 12, 2018 at 04:43:04PM +0100, Lajos Bodnar wrote:
> Thanks for your advice.
> I would like to write a function which run up if I open a haskell file.
> This function will ask a question automaticaly about that i would like to
> run the intero-mode or not.

Note that the `interactive' form is just "declarative", i.e.
it doesn't "do" anything on itself. It just states what kind
of parameters a function is going to take when invoked "as a
command", that is, from a key binding or similar.

The "magic" of asking for parameters happens there.

When that function is invoked from a hook this "magic" will be
missing :-) Besides, most hook functions are parameterless.

One way around it is asking the user actively. See for example
the function "read-from-minibuffer" (and perhaps most of the
chapter on minibuffers from the Emacs manual).

That said, to me, calling user interaction from a hook "feels"
a bit strange. But perhaps it's just me.

Cheers
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlqBvYQACgkQBcgs9XrR2kZveQCdHQG9Biu3wDCIhUpauInMsnQc
HTIAnil7u+iufFKdB/zDKpFjj1jtL6/6
=r1CJ
-----END PGP SIGNATURE-----



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

* Re: hook and interactive with parameter
       [not found]   ` <mailman.8974.1518450193.27995.help-gnu-emacs@gnu.org>
@ 2018-02-12 16:16     ` Emanuel Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2018-02-12 16:16 UTC (permalink / raw)
  To: help-gnu-emacs

Lajos Bodnar wrote:

> Thanks for your advice. I would like to write
> a function which run up if I open a haskell
> file. This function will ask a question
> automaticaly about that i would like to run
> the intero-mode or not.

I don't know if that is such a good idea, but
something like this would do it:

(defun ask-text-mode ()
  (when (yes-or-no-p "Activate text mode? ")
    (text-mode) ))

;; (setq nroff-mode-hook nil)
(defun nroff-mode-hook-temp-f ()
  (ask-text-mode) )
(add-hook 'nroff-mode-hook #'nroff-mode-hook-temp-f)

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: hook and interactive with parameter
       [not found]     ` <mailman.8981.1518452114.27995.help-gnu-emacs@gnu.org>
@ 2018-02-12 16:21       ` Emanuel Berg
  2018-02-13  8:23         ` Lajos Bodnar
  0 siblings, 1 reply; 12+ messages in thread
From: Emanuel Berg @ 2018-02-12 16:21 UTC (permalink / raw)
  To: help-gnu-emacs

tomas wrote:

> That said, to me, calling user interaction
> from a hook "feels" a bit strange.
> But perhaps it's just me.

No, hooks are often troublesome and the more you
put into them, the more trouble you get.
In this case while I don't think the computer
will blow up, I think the OP will be annoyed
with this question popping up all the time.
It isn't the Emacs way. And it is inefficient
as well as without it, say 50% of the times it
would be correct without any interference, now
you have to answer yes or no 100% of the
times instead.

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

* Re: hook and interactive with parameter
  2018-02-12 16:21       ` Emanuel Berg
@ 2018-02-13  8:23         ` Lajos Bodnar
  2018-02-13  8:42           ` Lajos Bodnar
                             ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Lajos Bodnar @ 2018-02-13  8:23 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

Thanks a lot,
I understood what the problem is with this concept.
What is your advice ?
The problem is that if I open a haskell file then sometimes I don't want to
run intero-mode with it (because the intero mode is very expensive).
In most cases I would like to run intero but not all time.

On Mon, Feb 12, 2018 at 5:21 PM, Emanuel Berg <moasen@zoho.com> wrote:

> tomas wrote:
>
> > That said, to me, calling user interaction
> > from a hook "feels" a bit strange.
> > But perhaps it's just me.
>
> No, hooks are often troublesome and the more you
> put into them, the more trouble you get.
> In this case while I don't think the computer
> will blow up, I think the OP will be annoyed
> with this question popping up all the time.
> It isn't the Emacs way. And it is inefficient
> as well as without it, say 50% of the times it
> would be correct without any interference, now
> you have to answer yes or no 100% of the
> times instead.
>
> --
> underground experts united
> http://user.it.uu.se/~embe8573
>


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

* Re: hook and interactive with parameter
  2018-02-13  8:23         ` Lajos Bodnar
@ 2018-02-13  8:42           ` Lajos Bodnar
  2018-02-13  8:44           ` Yuri Khan
                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Lajos Bodnar @ 2018-02-13  8:42 UTC (permalink / raw)
  To: help-gnu-emacs

Maybe I have to find a project/solution/workspace handler and if the opened
file is into these workspace then I will run intero-mode.

On Tue, Feb 13, 2018 at 9:23 AM, Lajos Bodnar <bodnarlajoska@gmail.com>
wrote:

> Thanks a lot,
> I understood what the problem is with this concept.
> What is your advice ?
> The problem is that if I open a haskell file then sometimes I don't want
> to run intero-mode with it (because the intero mode is very expensive).
> In most cases I would like to run intero but not all time.
>
> On Mon, Feb 12, 2018 at 5:21 PM, Emanuel Berg <moasen@zoho.com> wrote:
>
>> tomas wrote:
>>
>> > That said, to me, calling user interaction
>> > from a hook "feels" a bit strange.
>> > But perhaps it's just me.
>>
>> No, hooks are often troublesome and the more you
>> put into them, the more trouble you get.
>> In this case while I don't think the computer
>> will blow up, I think the OP will be annoyed
>> with this question popping up all the time.
>> It isn't the Emacs way. And it is inefficient
>> as well as without it, say 50% of the times it
>> would be correct without any interference, now
>> you have to answer yes or no 100% of the
>> times instead.
>>
>> --
>> underground experts united
>> http://user.it.uu.se/~embe8573
>>
>
>


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

* Re: hook and interactive with parameter
  2018-02-13  8:23         ` Lajos Bodnar
  2018-02-13  8:42           ` Lajos Bodnar
@ 2018-02-13  8:44           ` Yuri Khan
  2018-02-13  8:51           ` tomas
       [not found]           ` <mailman.9028.1518511493.27995.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 12+ messages in thread
From: Yuri Khan @ 2018-02-13  8:44 UTC (permalink / raw)
  To: Lajos Bodnar; +Cc: help-gnu-emacs, Emanuel Berg

On Tue, Feb 13, 2018 at 3:23 PM, Lajos Bodnar <bodnarlajoska@gmail.com> wrote:

> What is your advice ?
> The problem is that if I open a haskell file then sometimes I don't want to
> run intero-mode with it (because the intero mode is very expensive).
> In most cases I would like to run intero but not all time.

Option 1: Bind intero-mode to an easy key, such as <f9>. Press it
after opening each file. In term of keypresses, pressing <f9> is not
much worse than pressing “y” when you want to enable the mode, and not
pressing <f9> is cheaper than pressing “n” when you don’t.

Option 2: Enable intero-mode from the hook unconditionally and
tolerate the expensiveness. Maybe bind a key to disable the mode.

Option 3: Enable intero-mode dependent on a variable, let’s say,
“my-enable-intero-mode”. Manage it as a file-local or directory-local
variable.



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

* Re: hook and interactive with parameter
  2018-02-13  8:23         ` Lajos Bodnar
  2018-02-13  8:42           ` Lajos Bodnar
  2018-02-13  8:44           ` Yuri Khan
@ 2018-02-13  8:51           ` tomas
  2018-02-13  9:05             ` Lajos Bodnar
       [not found]           ` <mailman.9028.1518511493.27995.help-gnu-emacs@gnu.org>
  3 siblings, 1 reply; 12+ messages in thread
From: tomas @ 2018-02-13  8:51 UTC (permalink / raw)
  To: Lajos Bodnar; +Cc: help-gnu-emacs, Emanuel Berg

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Feb 13, 2018 at 09:23:41AM +0100, Lajos Bodnar wrote:
> Thanks a lot,
> I understood what the problem is with this concept.
> What is your advice ?
> The problem is that if I open a haskell file then sometimes I don't want to
> run intero-mode with it (because the intero mode is very expensive).
> In most cases I would like to run intero but not all time.

I'd go with experimenting. After all, a diffuse feeling by
Emanuel and me is less worth than hard-nosed experience :-)

So hook away, and either use yes-or-no-p (or its less verbose
sister y-or-n-p), as Emanuel suggested -- or the more complex
(but better tunable) minibuffer stuff. Find out what breaks
(if at all: hunches are, after all, just... hunches :)

Just to get you jumpsterted: this seems to work, more or less.
Fine tuning is left as an exercise for the reader :)

  (defun my-confirm-extra-toppings ()
    (when (y-or-n-p "With extra toppings? ")
      ;; just to show something:
      (set-background-color "lightblue")))
  
  (add-hook 'find-file-hook 'my-confirm-extra-toppings)

Enjoy :-)

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlqCpyQACgkQBcgs9XrR2kaltACeMLATdhMYn8fFK/0H7FDUhL7m
Q9oAnRN/fm0o/AH9lRGHr6GJOSE18Bke
=Hrn/
-----END PGP SIGNATURE-----



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

* Re: hook and interactive with parameter
  2018-02-13  8:51           ` tomas
@ 2018-02-13  9:05             ` Lajos Bodnar
  0 siblings, 0 replies; 12+ messages in thread
From: Lajos Bodnar @ 2018-02-13  9:05 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs, Emanuel Berg

Thanks a lot,
I overall solution will be that when a haskell file is opened and I push
the F9 button then I will look over that where the haskell project root is
(.git folder or stack.yaml file).
I will add this path to my-opened-projects list and if I open a new haskell
file I will check that the file is under these path and I will run
intero-mode automatically.
It will based on the .git folder or the stack.yaml file or ...
The other cases I will run intero-mode manually if it is neccessary.
There is another advantage with this solution that I can open a filtered
minibuffer with only the opened "project" files.

regards
Lajos


On Tue, Feb 13, 2018 at 9:51 AM, <tomas@tuxteam.de> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tue, Feb 13, 2018 at 09:23:41AM +0100, Lajos Bodnar wrote:
> > Thanks a lot,
> > I understood what the problem is with this concept.
> > What is your advice ?
> > The problem is that if I open a haskell file then sometimes I don't want
> to
> > run intero-mode with it (because the intero mode is very expensive).
> > In most cases I would like to run intero but not all time.
>
> I'd go with experimenting. After all, a diffuse feeling by
> Emanuel and me is less worth than hard-nosed experience :-)
>
> So hook away, and either use yes-or-no-p (or its less verbose
> sister y-or-n-p), as Emanuel suggested -- or the more complex
> (but better tunable) minibuffer stuff. Find out what breaks
> (if at all: hunches are, after all, just... hunches :)
>
> Just to get you jumpsterted: this seems to work, more or less.
> Fine tuning is left as an exercise for the reader :)
>
>   (defun my-confirm-extra-toppings ()
>     (when (y-or-n-p "With extra toppings? ")
>       ;; just to show something:
>       (set-background-color "lightblue")))
>
>   (add-hook 'find-file-hook 'my-confirm-extra-toppings)
>
> Enjoy :-)
>
> Cheers
> - -- t
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
>
> iEYEARECAAYFAlqCpyQACgkQBcgs9XrR2kaltACeMLATdhMYn8fFK/0H7FDUhL7m
> Q9oAnRN/fm0o/AH9lRGHr6GJOSE18Bke
> =Hrn/
> -----END PGP SIGNATURE-----
>


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

* Re: hook and interactive with parameter
       [not found]           ` <mailman.9028.1518511493.27995.help-gnu-emacs@gnu.org>
@ 2018-02-13 19:02             ` Emanuel Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2018-02-13 19:02 UTC (permalink / raw)
  To: help-gnu-emacs

Yuri Khan wrote:

> Option 1: Bind intero-mode to an easy key,
> such as <f9>. Press it after opening each
> file. In term of keypresses, pressing <f9> is
> not much worse than pressing “y” when you
> want to enable the mode, and not pressing
> <f9> is cheaper than pressing “n” when you
> don’t.

Yes, this is the best idea.

If you notice that for certain files
(particular files) you always do this, you can
use this

    (setq magic-mode-alist '(("/\\* cpp \\*/" . c++-mode)))

for those files, only adapted to Haskell, not
C++.

To test it, put

/* cpp */

as the first line in a file called cpp.txt -
now, the ".txt" extention should put the file
in text mode. But eval the above form, close
the file, and open it again - now it should be
in C++.

Magic :)

-- 
underground experts united
http://user.it.uu.se/~embe8573


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

end of thread, other threads:[~2018-02-13 19:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-12 10:03 hook and interactive with parameter Lajos Bodnar
     [not found] <mailman.8968.1518443498.27995.help-gnu-emacs@gnu.org>
2018-02-12 15:28 ` Emanuel Berg
2018-02-12 15:43   ` Lajos Bodnar
2018-02-12 16:15     ` tomas
     [not found]     ` <mailman.8981.1518452114.27995.help-gnu-emacs@gnu.org>
2018-02-12 16:21       ` Emanuel Berg
2018-02-13  8:23         ` Lajos Bodnar
2018-02-13  8:42           ` Lajos Bodnar
2018-02-13  8:44           ` Yuri Khan
2018-02-13  8:51           ` tomas
2018-02-13  9:05             ` Lajos Bodnar
     [not found]           ` <mailman.9028.1518511493.27995.help-gnu-emacs@gnu.org>
2018-02-13 19:02             ` Emanuel Berg
     [not found]   ` <mailman.8974.1518450193.27995.help-gnu-emacs@gnu.org>
2018-02-12 16:16     ` Emanuel Berg

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.