Loading ...
Sorry, an error occurred while loading the content.
 

open, save hooks?

Expand Messages
  • Kimmo Pietarinen
    I miss the functionality that is found for example in vim that the cursor position is saved for visited files and restored when the file is re-opened. I know
    Message 1 of 4 , Dec 22, 2004

      I miss the functionality that is found for example in vim that the cursor position is saved for visited files and restored when the file is re-opened. I know that it is possible to get a somewhat similar functionality by using the -c flag to 'me', but I do not want 'me' to restore my entire previous session including open files etc.

       

      Ok, so I though I would have this as a small Chrismas project and implement a macro that does this. I am new to macro programming and have only done some small macros previously. I have searched the help pages but not really figured out how to intercept the file open and save commands. Is it possible to do and what hooks or callbacks should I use? I have tried to do something with $buffer-fhook, $buffer-bhook and $buffer-dhook, but they do not seem really appropriate...

       

      Thanks,

      Kimmo

      Online Virus Test: Scanna din computer GRATIS online-scanna

    • Jon Green
      ... Hi Kimmo, I m not that familier with VIM. So to clarify what you are saying then if a file is opened that was opened in a previous session then the file
      Message 2 of 4 , Dec 22, 2004
        Kimmo Pietarinen wrote:
        > I miss the functionality that is found for example in vim that the
        > cursor position is saved for visited files and restored when the file is
        > re-opened. I know that it is possible to get a somewhat similar
        > functionality by using the -c flag to 'me', but I do not want 'me' to
        > restore my entire previous session including open files etc.
        >

        Hi Kimmo,

        I'm not that familier with VIM. So to clarify what you are saying then
        if a file is opened that was opened in a previous session then the file
        position (line/col) is restored as the starting point.

        Like you say similar to -c. The difference being is that you open the
        file yourself from a 'blank' session (or one with say a few files
        loaded). I assume that there is a limit on the "visited" files - would
        this be the last 10 files perhaps ?

        Jon.

        >
        >
        > Ok, so I though I would have this as a small Chrismas project and
        > implement a macro that does this. I am new to macro programming and have
        > only done some small macros previously. I have searched the help pages
        > but not really figured out how to intercept the file open and save
        > commands. Is it possible to do and what hooks or callbacks should I use?
        > I have tried to do something with $buffer-fhook, $buffer-bhook and
        > $buffer-dhook, but they do not seem really appropriate...

        No the fhook mechanism is template (language) specific it is not generic
        enough to cater for all files. The all file hook was discussed some
        time ago but I do not think it is in the current public release build.
      • Steven Phillips
        Kimmo, It is dangerous to do something like this too low down as it can break other things, for example the CVS interface loads the CVS/Entries file and if
        Message 3 of 4 , Dec 22, 2004
          Kimmo,

          It is dangerous to do something like this too low down as it can break other
          things, for example the CVS interface loads the CVS/Entries file and if your
          extension made the file load and go to line 20 the cvs directory list would
          not be correct, there are plenty of other examples.

          I think the best way to do this would be to write a wrapper around the
          find-file command and bind the new macro to C-x C-f, i.e.

          define-macro my-find-file
          find-file ....
          !if '$buffer-fname in list' and 'file just loaded'
          goto-line ...
          !endif
          !emacro
          global-bind-key my-find-file "C-x C-f"

          You may find that you have to replace a couple of commands but the side effect
          are far easier to control. The difficulty with this is to actually store the
          final cursor position of each file as it is deleted and this will require a
          little hacking in the macro release.

          The best mechanism to use would be the very little used $buffer-dhook variable which
          can be set to the name of a macro which will be called when the buffer is
          deleted. The only difficulty is setting this variable and the only solution I
          can think of that's near reasonable is to modify the buffer-init function in
          buffinit.emf (look for the setting of $buffer-fhook) to simply set this
          variable to your macro. You will also need to create an fhook-default to
          handle general files without a hook.

          I have been thinking for some time that if a 'my-fhook-always' macro exists
          then it is called for all files loaded, perhaps this can be addressed for the
          next release so you would be able to remove your changes from buffinit.

          Steve

          > Subject: [jasspa] open, save hooks?
          > From: Kimmo Pietarinen <kipi@...>
          > Date: Wednesday, December 22, 2004, 9:52:43 PM
          > To: "jasspa group" <jasspa@yahoogroups.com>
          > I miss the functionality that is found for example in vim that the cursor
          > position is saved for visited files and restored when the file is re-opened.
          > I know that it is possible to get a somewhat similar functionality by using
          > the -c flag to 'me', but I do not want 'me' to restore my entire previous
          > session including open files etc.

          >  

          > Ok, so I though I would have this as a small Chrismas project and
          > implement a macro that does this. I am new to macro programming and have
          > only done some small macros previously. I have searched the help pages but
          > not really figured out how to intercept the file open and save commands. Is
          > it possible to do and what hooks or callbacks should I use? I have tried to
          > do something with $buffer-fhook, $buffer-bhook and $buffer-dhook, but they
          > do not seem really appropriate...

          >  

          > Thanks,

          > Kimmo

          > Online Virus Test: Scanna din computer GRATIS online-scanna





          > __________________________________________________________________________

          > This is an unmoderated list. JASSPA is not responsible for the content of
          > any material posted to this list.

          > To unsubscribe, send a mail message to

          >     mailto:jasspa-unsubscribe@yahoogroups.com

          > or visit http://groups.yahoo.com/group/jasspa and
          > modify your account settings manually.





          > Yahoo! Groups SponsorGet unlimited calls to

          > U.S./Canada




          > Yahoo! Groups Links
          > To visit your group on the web, go to:
          > http://groups.yahoo.com/group/jasspa/
          >  To unsubscribe from this group, send an email to:
          > jasspa-unsubscribe@yahoogroups.com
          >  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
        • Kimmo Pietarinen
          Thanks for your tips! I think it would be a great idea to implement the fhook-always/my-fhook-always macros. Btw, shouldn t I receive all mails posted to this
          Message 4 of 4 , Dec 28, 2004
            Thanks for your tips! I think it would be a great idea to implement the
            fhook-always/my-fhook-always macros.

            Btw, shouldn't I receive all mails posted to this mail group if I have
            joined the jasspa mail list? I have so far not received anything. Maybe it
            is may e-mail providers SPAM filter that stops the mails?

            /Kimmo

            > Subject: Re: [jasspa] open, save hooks?
            > From: Steven Phillips <bill@j...>
            > Date: Wed Dec 22, 2004 11:17 pm
            > To: "jasspa group" <jasspa@yahoogroups.com>
            > Kimmo,
            >
            >It is dangerous to do something like this too low down as it can break
            >other
            >things, for example the CVS interface loads the CVS/Entries file and if
            >your
            >extension made the file load and go to line 20 the cvs directory list would
            >not be correct, there are plenty of other examples.
            >
            >I think the best way to do this would be to write a wrapper around the
            >find-file command and bind the new macro to C-x C-f, i.e.
            >
            >define-macro my-find-file
            >find-file ....
            >!if '$buffer-fname in list' and 'file just loaded'
            >goto-line ...
            >!endif
            >!emacro
            >global-bind-key my-find-file "C-x C-f"
            >
            >You may find that you have to replace a couple of commands but the side
            >effect
            >are far easier to control. The difficulty with this is to actually store
            >the
            >final cursor position of each file as it is deleted and this will require a
            >little hacking in the macro release.
            >
            >The best mechanism to use would be the very little used $buffer-dhook
            >variable
            >which
            >can be set to the name of a macro which will be called when the buffer is
            >deleted. The only difficulty is setting this variable and the only solution
            >I
            >can think of that's near reasonable is to modify the buffer-init function
            >in
            >buffinit.emf (look for the setting of $buffer-fhook) to simply set this
            >variable to your macro. You will also need to create an fhook-default to
            >handle general files without a hook.
            >
            >I have been thinking for some time that if a 'my-fhook-always' macro exists
            >then it is called for all files loaded, perhaps this can be addressed for
            >the
            >next release so you would be able to remove your changes from buffinit.
            >
            >Steve
          Your message has been successfully submitted and would be delivered to recipients shortly.