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

Retrieving default values of options from a script

Expand Messages
  • Nikolai Weibull
    I would like to know the default value for fileformat while executing a script. The only way I ve come up with is to: let ff_save = &fileformat set
    Message 1 of 4 , Nov 19, 2005
    • 0 Attachment
      I would like to know the default value for 'fileformat' while executing
      a script. The only way I've come up with is to:

      let ff_save = &fileformat
      set fileformat&
      let ff_default = &fileformat
      let &fileformat = ff_save

      and ff_default will contain the default value for 'fileformat'. The
      only problem with this is that setting 'fileformat' isn't good, as it
      will update 'modified' under the wrong conditions. It also won't work
      if the file isn't 'modifiable'. So I was wondering how to get at the
      default value without disturbing the setting itself? One idea I had was
      to allow for:

      let ff_default = &fileformat&,

      i.e., the "&" suffix will give you the default value of the given
      option.

      So, to summarize:

      1 Is there already a way to get at the default value?

      2 If not, could we please add a way to do it?

      Thanks.

      nikolai

      --
      Nikolai Weibull: now available free of charge at http://bitwi.se/!
      Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
      main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
    • A. J. Mechelynck
      ... In the case of the fileformat option, you can get the default as follows: if has( unix ) let ff_default = unix elseif has( mac ) let ff_default =
      Message 2 of 4 , Nov 19, 2005
      • 0 Attachment
        Nikolai Weibull wrote:
        > I would like to know the default value for 'fileformat' while executing
        > a script. The only way I've come up with is to:
        >
        > let ff_save = &fileformat
        > set fileformat&
        > let ff_default = &fileformat
        > let &fileformat = ff_save
        >
        > and ff_default will contain the default value for 'fileformat'. The
        > only problem with this is that setting 'fileformat' isn't good, as it
        > will update 'modified' under the wrong conditions. It also won't work
        > if the file isn't 'modifiable'. So I was wondering how to get at the
        > default value without disturbing the setting itself? One idea I had was
        > to allow for:
        >
        > let ff_default = &fileformat&,
        >
        > i.e., the "&" suffix will give you the default value of the given
        > option.
        >
        > So, to summarize:
        >
        > 1 Is there already a way to get at the default value?
        >
        > 2 If not, could we please add a way to do it?
        >
        > Thanks.
        >
        > nikolai
        >

        In the case of the 'fileformat' option, you can get the default as follows:

        if has("unix")
        let ff_default = "unix"
        elseif has("mac")
        let ff_default = "mac"
        elseif has("win32")
        \ || has("win64")
        \ || has("win16")
        \ || has("dos32")
        \ || has("dos16")
        \ || has("os2")
        let ff_default = "dos"
        else
        " what are we running on? VMS maybe?
        echomsg "Cannot determine default fileformat"
        let ff_default = ""
        endif

        see ":help 'fileformat'".

        This intentionally does not take into account the automatic fileformat
        detection done when starting to edit an existing file if 'fileformats'
        (plural) is nonempty.

        In general, for most options (with a few exceptions like 'encoding') a
        human like you or me can read option defaults from the help entry for
        the relevant option. This, however, does not apply to scripts (unless
        you want to read the default off $VIMRUNTIME/doc/options.txt in the
        script, which may be possible but is inelegant); however, most options
        either have a single default, or have a few defaults according to which
        platform the program is running on, or of whether it's a console version
        or a GUI, and that can be determined by means of the has() function.

        See
        :help has()
        :help feature-list


        Best regards,
        Tony.
      • Nikolai Weibull
        ... [Long and complicated way of getting at the default that doesn t take into acount things such as changes to the default (new operating systems, and so on),
        Message 3 of 4 , Nov 19, 2005
        • 0 Attachment
          A. J. Mechelynck wrote:

          > Nikolai Weibull wrote:

          > > I would like to know the default value for 'fileformat' while
          > > executing a script.

          > In the case of the 'fileformat' option, you can get the default as
          > follows:

          [Long and complicated way of getting at the default that doesn't take
          into acount things such as changes to the default (new operating
          systems, and so on), which only works for the 'fileformat' option.]

          Yes, I know exactly how to do what you describe. Your response actually
          surprises me and I actually feel a bit offended by it. I thought it to
          be obvious that I wasn't asking for a way of simulating the default. I
          was asking for a way to get the _actual_ default, whatever that may be.
          More in the sense of "can we please add a method to do so" than of "I
          haven't read the docs and I don't know what to do", seeing as how I
          described the behavior of the option in question.

          Actually, now that we have hashes in Vim 7, why not provided a hash that
          has the names of options as keys and their values as, well, its values?
          Perhaps also one that has the default values as its values.

          nikolai

          --
          Nikolai Weibull: now available free of charge at http://bitwi.se/!
          Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
          main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
        • A. J. Mechelynck
          ... [...] ... Rest assured that there was no intention to offend you. There are users of all competence levels on this list; and I was just trying to help you,
          Message 4 of 4 , Nov 19, 2005
          • 0 Attachment
            Nikolai Weibull wrote:
            > A. J. Mechelynck wrote:
            [...]
            > [Long and complicated way of getting at the default that doesn't take
            > into acount things such as changes to the default (new operating
            > systems, and so on), which only works for the 'fileformat' option.]
            >
            > Yes, I know exactly how to do what you describe. Your response actually
            > surprises me and I actually feel a bit offended by it. I thought it to
            > be obvious that I wasn't asking for a way of simulating the default. I
            > was asking for a way to get the _actual_ default, whatever that may be.
            > More in the sense of "can we please add a method to do so" than of "I
            > haven't read the docs and I don't know what to do", seeing as how I
            > described the behavior of the option in question.
            >
            > Actually, now that we have hashes in Vim 7, why not provided a hash that
            > has the names of options as keys and their values as, well, its values?
            > Perhaps also one that has the default values as its values.
            >
            > nikolai
            >

            Rest assured that there was no intention to offend you. There are users
            of all competence levels on this list; and I was just trying to help
            you, showing how I might do it. BTW, it is not so "long and
            complicated"; it's just an implementation of what option.txt says as

            *'fileformat'* *'ff'*
            'fileformat' 'ff' string (MS-DOS, MS-Windows, OS/2 default: "dos",
            Unix default: "unix",
            Macintosh default: "mac")

            The reason it is as long as it is, is that there is no single "has()"
            feature name common to all versions of Dos, Windows, and OS/2. If it can
            be assumed that all non-Mac non-Unix systems are Dos, Windows or OS/2,
            then the third "elseif" can be replaced by "else" and the existing
            "else" clause (with its message) deleted altogether.

            About "hashes" (do you mean "dictionaries"?), I don't make the policy
            decisions for Vim, and I don't write Vim code except in very simple
            cases. I suppose that the solution you mention above might be feasible,
            but that's for Bram to decide.


            Best regards,
            Tony.
          Your message has been successfully submitted and would be delivered to recipients shortly.