Sunday, May 31, 2020

Re: function definition for only one file, not for other simultaneously opened files

On Sun, May 31, 2020 at 2:49 AM Gary Johnson <garyjohn@spocom.com> wrote:
>
> On 2020-05-31, Manas wrote:
> > I am struggling to find a way to deal with the following problem.
> >
> > Suppose, I open 3 markdown files at once in separate tabs. Now I want some
> > particular function for one of those files only. Like, I want to add time and
> > date in front of each new line for that file. So I define a function to do so.
> > But, that function is affecting other files too which I don't want.
> >
> > Is there some way to achieve that?
>
> From ":help local-function":
>
> There are only script-local functions, no buffer-local or
> window-local functions.
>
> However, you _can_ control how and when your function is executed.
> For example, mappings and autocommands can be local to a buffer.
> You can also have your function look at the current buffer name or
> some other property of the buffer and decide whether to continue
> executing or to return immediately.
>
> How are you executing your function and what is it doing to affect
> files or buffers that you don't want it to?
>
> Regards,
> Gary

Sidestepping for the moment the question of :def functions which are
still "under development":
- a function can be global (:function foo() ), script-local (:function
s:bar() ) or defined in an autoload-script (:function tiddly#Wink()
defined in e.g. ~/.vim/autoload/tiddly.vim ). Script-local functions
are only visible from the same script, including autocommands defined
there. To invoke them from mappings, replace s: by <SID>
- a function can be assigned to a Funcref which is a variable (global,
script-local, buffer-local, window-local, etc.) of a special type;
that Funcref can then be used both as a variable (when not followed by
() ) or as a function (followed by () ).
- a function can also be invoked from a user-command (defined by the
:command command)

I have a kind of hunch that there is something for you (Manas) in the
above but I'm not sure what.


Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXu2DCASY0UZUzC75oUM4g0pccw0vu_wH5ApXKMg%2BTLqrQ%40mail.gmail.com.

No comments: