Skip to content

Default transforms and variables

Benjamin Gray edited this page Jul 31, 2020 · 2 revisions

All default resolvers have priority -1, so are easily overwritten with custom handlers.

Default named transforms

The default provider supports the following named transforms:

  • upcase: Uppercases the input
  • downcase: Lowercases the input

Default variables

The default provider supports the following variables:

  • TM_CURRENT_LINE: The text of the line the snippet was expanded on. Currently removes the prefix if present, but the desired behaviour is to be consistent with TextMate (wanting TextMate consistency applies to all TM_... variables).
  • TM_CURRENT_WORD: The word around the cursor the snippet is being inserted into, as defined by Cursor::getCurrentWordBufferRange.
  • TM_DIRECTORY: The directory path of the editor being expanded into. Fails to resolve if the file is not saved to the filesystem.
  • TM_FILENAME: The filename of the editor. Resolves to untitled if the editor is not named.
  • TM_FILENAME_BASE: The filename of the editor, without the extension if it has one. Unnamed editor has same semantics as TM_FILENAME.
  • TM_FILEPATH: The path of the editor, including the filename. Has same semantics as TM_DIRECTORY for editors not saved to the filesystem.
  • TM_LINE_INDEX: The row index (0-based) the snippet was expanded on. Note this is constant; it does not change for multiline snippets.
  • TM_LINE_NUMBER: The line number (1-based) the snippet was expanded on. Has same multiline semantics as TM_LINE_INDEX.
  • TM_SELECTED_TEXT: The text in the latest selection of the editor.
  • CLIPBOARD: The contents at the top of the clipboard.
  • CURRENT_YEAR: The current year in long format (e.g., 2020).
  • CURRENT_YEAR_SHORT: The current year in 2-digit short format (e.g., 20).
  • CURRENT_MONTH: The current month as a 2-digit number (e.g., 07).
  • CURRENT_MONTH_NAME: The current month name (e.g., February).
  • CURRENT_MONTH_NAME_SHORT: The shortened current month name (e.g., Feb).
  • CURRENT_DATE: The day of the month as a 2-digit number (e.g., 31).
  • CURRENT_DAY_NAME: The name of the day (e.g., Friday).
  • CURRENT_DAY_NAME_SHORT: The shortened name of the day (e.g., Fri).
  • CURRENT_HOUR: The current hour in 24 hour time, with 2 digits (e.g., 22).
  • CURRENT_MINUTE: The current minute with 2 digits (e.g., 03).
  • CURRENT_SECOND: The current second with 2 digits (e.g., 09).
  • CURRENT_SECONDS_UNIX: The current time in seconds since the Unix epoch (e.g., 1596200526).
  • BLOCK_COMMENT_START: The starting block comment characters of the language at the start of the insertion range. Supports embedded grammars. If the characters are unknown (or don't exist), it is unresolved. Support for comment characters is manual right now, so many are missing.
  • BLOCK_COMMENT_END: The end block comment characters. See BLOCK_COMMENT_START for semantic details.
  • LINE_COMMENT: The line comment characters. See BLOCK_COMMENT_START for semantic details.

All default variables also have tests that can demonstrate expected behaviour. These tests should catch edge cases, so please make a PR to expand them if you can see something they might be missing.

Clone this wiki locally