Class: Rvim::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/rvim/settings.rb

Constant Summary collapse

DEFAULTS =
{
  hlsearch: true,
  ignorecase: false,
  shiftwidth: 2,
  number: false,
  relativenumber: false,
  smartcase: false,
  syntax: :auto,
  wrap: true,
  tabstop: 8,
  scrolloff: 0,
  cursorline: false,
  ruler: true,
  list: false,
  foldenable: true,
  foldmethod: 'manual',
  foldlevel: 99,
  modeline: true,
  modelines: 5,
  undofile: false,
  wildmenu: true,
  spell: false,
  spelllang: 'en',
  tags: './tags,tags',
  textwidth: 78,
  makeprg: 'make',
  grepprg: 'grep -n $* /dev/null',
  errorformat: '%f:%l:%c:%m,%f:%l:%m',
  expandtab: false,
  listchars: 'tab:> ,trail:ยท',
  colorcolumn: '',
  cursorcolumn: false,
  fileformat: 'unix',
  statusline: '',
  fileencoding: 'utf-8',
  virtualedit: '',
  mouse: '',
  sidescrolloff: 0,
  splitright: false,
  splitbelow: false,
  showmode: true,
  incsearch: true,
  lazyredraw: false,
  autowrite: false,
  equalalways: true,
  history: 100,
  autoindent: false,
  laststatus: 2,
  nrformats: 'bin,hex',
  smartindent: false,
  startofline: true,
  keywordprg: 'man',
  pumheight: 0,
  linebreak: false,
  backup: false,
  confirm: false,
  title: false,
  titlestring: '',
  showtabline: 1,
  scrolljump: 1,
  backupext: '~',
  backupdir: '.',
  showbreak: '',
  tildeop: false,
  writebackup: true,
  shell: '/bin/sh',
  autoread: false,
  hidden: true,
  undolevels: 1000,
  numberwidth: 4,
  formatprg: '',
  paste: false,
  pastetoggle: '',
  wildignore: '',
  endofline: true,
  infercase: false,
  equalprg: '',
  breakindent: false,
  fixendofline: true,
  shellcmdflag: '-c',
  grepformat: '%f:%l:%c:%m,%f:%l:%m',
  belloff: 'all',
  signcolumn: 'auto',
  updatetime: 4000,
  shortmess: 'filnxtToOS',
  clipboard: '',
  background: 'dark',
  switchbuf: 'uselast',
  magic: true,
  eadirection: 'both',
  completeopt: 'menu',
  timeout: true,
  timeoutlen: 1000,
  ttimeoutlen: -1,
  isfname: '@,48-57,/,.,-,_,+,,,#,$,%,~,=',
  isident: '@,48-57,_,192-255',
  wrapscan: true,
  cmdheight: 1,
  report: 2,
  iskeyword: '@,48-57,_,192-255',
  matchpairs: '(:),{:},[:]',
  formatoptions: 'tcq',
  comments: 's1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-',
  commentstring: '/*%s*/',
  path: '.,,',
  winminheight: 1,
  winheight: 1,
  winwidth: 20,
  winminwidth: 1,
  synmaxcol: 3000,
  redrawtime: 2000,
  cindent: false,
  cinoptions: '',
  cinwords: 'if,else,while,do,for,switch',
  lisp: false,
  lispwords: 'defun,define,defmacro,set!,lambda,if,case,let,flet,let*,letrec,do,do*,define-syntax,let-syntax,letrec-syntax,destructuring-bind,defpackage,defparameter,defstruct,deftype,defvar,do-all-symbols,do-external-symbols,do-symbols,dolist,dotimes,ecase,etypecase,eval-when,labels,macrolet,multiple-value-bind,multiple-value-prog1,multiple-value-setq,prog1,progv,typecase,unless,unwind-protect,when,with-input-from-string,with-open-file,with-open-stream,with-output-to-string,with-package-iterator,define-condition,handler-bind,handler-case,restart-bind,restart-case,with-simple-restart,store-value,use-value,muffle-warning,abort,continue',
  softtabstop: 0,
  smarttab: true,
  wrapmargin: 0,
  selection: 'inclusive',
  selectmode: '',
  conceallevel: 0,
  concealcursor: '',
  breakat: " \t!@*-+;:,./?",
  matchtime: 5,
  cmdwinheight: 7,
  swapfile: true,
  directory: '.,~/tmp,/var/tmp,/tmp',
  updatecount: 200,
  viewdir: '~/.vim/view',
  viewoptions: 'folds,cursor,curdir',
  runtimepath: '~/.vim,/usr/share/vim/vimfiles,/usr/share/vim,/usr/share/vim/vimfiles/after,~/.vim/after',
  cdpath: ',,',
  define: '^\s*#\s*define',
  include: '^\s*#\s*include',
  sessionoptions: 'blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal',
  cpoptions: 'aABceFs',
  display: 'lastline',
  fillchars: '',
  tabline: '',
  verbose: 0,
  scrollbind: false,
  cursorbind: false,
  shellpipe: '2>&1| tee',
  shellredir: '>%s 2>&1',
  shellslash: false,
  cinkeys: '0{,0},0),0],:,0#,!^F,o,O,e',
  helpheight: 20,
  helplang: 'en',
  tagcase: 'followic',
  tagstack: true,
  mousehide: true,
  mousemodel: 'extend',
  mousetime: 500,
  iminsert: 0,
  imsearch: -1,
  langmap: '',
  langremap: false,
  regexpengine: 0,
  taglength: 0,
  tagrelative: true,
  wildchar: 9,
  wildcharm: 0,
  wildmode: 'full',
  previewheight: 12,
  joinspaces: true,
  winfixheight: false,
  winfixwidth: false,
  cscopetag: false,
  cscopeprg: 'cscope',
  cscopetagorder: 0,
  viminfo: "!,'100,<50,s10,h",
  complete: '.,w,b,u,t',
  dictionary: '',
  thesaurus: '',
  gdefault: false,
  secure: false,
  exrc: false,
  more: true,
  cedit: "\x06",
  wildoptions: '',
  casemap: 'internal,keepascii',
  quoteescape: '\\',
  formatlistpat: '^\s*\d\+[\]:.)}\t ]\s*',
  keymap: '',
  winaltkeys: 'menu',
  omnifunc: '',
  operatorfunc: '',
  tagfunc: '',
  formatexpr: '',
  indentexpr: '',
  indentkeys: '0{,0},0),0],:,0#,!^F,o,O,e',
  foldexpr: '0',
  foldtext: 'foldtext()',
  foldminlines: 1,
  foldnestmax: 20,
  errorbells: false,
  visualbell: false,
  ttyfast: true,
  termguicolors: false,
  termencoding: '',
  spellcapcheck: '[.?!]\_[\])\'"\t ]\+',
  spellfile: '',
  spellsuggest: 'best',
  spelloptions: '',
  digraph: false,
  revins: false,
  rightleft: false,
  rightleftcmd: 'search',
  fileformats: 'unix,dos',
  fileignorecase: false,
  maxmem: 1_048_576,
  maxmempattern: 1000,
  maxmemtot: 1_048_576,
  maxmapdepth: 1000,
  maxfuncdepth: 100,
  write: true,
  writeany: false,
  writedelay: 0,
  autowriteall: false,
  fsync: false,
  delcombine: false,
  emoji: true,
  terse: false,
  warn: true,
  tagbsearch: true,
  sidescroll: 0,
  pumwidth: 15,
  splitkeep: 'cursor',
  suffixes: '.bak,~,.o,.h,.info,.swp,.obj',
  suffixesadd: '',
  filetype: '',
  eventignore: '',
  wildignorecase: false,
  loadplugins: true,
  tabpagemax: 50,
  printheader: '%<%f%h%m%=Page %N',
  printoptions: '',
  printfont: 'courier',
  printencoding: '',
  printexpr: '',
  cscoperelative: false,
  cscopepathcomp: 0,
  cscopequickfix: '',
  cscopeverbose: false,
  ttimeout: true,
  isprint: '@,161-255',
  helpfile: '$VIMRUNTIME/doc/help.txt',
  langnoremap: true,
  langmenu: '',
  quickfixtextfunc: '',
  inccommand: 'nosplit',
  pumblend: 0,
  winblend: 0,
  mousescroll: 'ver:3,hor:6',
  cinscopedecls: 'public,protected,private',
  restorescreen: true,
  lispoptions: '',
  viminfofile: '',
  smoothscroll: false,
  statuscolumn: '',
}.freeze
ALIASES =
{
  'hls' => :hlsearch,
  'ic' => :ignorecase,
  'nu' => :number,
  'rnu' => :relativenumber,
  'scs' => :smartcase,
  'sw' => :shiftwidth,
  'syn' => :syntax,
  'ts' => :tabstop,
  'so' => :scrolloff,
  'cul' => :cursorline,
  'ru' => :ruler,
  'fen' => :foldenable,
  'fdm' => :foldmethod,
  'fdl' => :foldlevel,
  'ml' => :modeline,
  'mls' => :modelines,
  'udf' => :undofile,
  'wmnu' => :wildmenu,
  'tw' => :textwidth,
  'mp' => :makeprg,
  'gp' => :grepprg,
  'efm' => :errorformat,
  'et' => :expandtab,
  'lcs' => :listchars,
  'cc' => :colorcolumn,
  'cuc' => :cursorcolumn,
  'ff' => :fileformat,
  'stl' => :statusline,
  'fenc' => :fileencoding,
  've' => :virtualedit,
  'siso' => :sidescrolloff,
  'spr' => :splitright,
  'sb' => :splitbelow,
  'smd' => :showmode,
  'is' => :incsearch,
  'lz' => :lazyredraw,
  'aw' => :autowrite,
  'ea' => :equalalways,
  'hi' => :history,
  'ai' => :autoindent,
  'ls' => :laststatus,
  'nf' => :nrformats,
  'si' => :smartindent,
  'sol' => :startofline,
  'kp' => :keywordprg,
  'ph' => :pumheight,
  'lbr' => :linebreak,
  'bk' => :backup,
  'cf' => :confirm,
  'tl' => :title,
  'stl_str' => :titlestring,
  'stal' => :showtabline,
  'sj' => :scrolljump,
  'bex' => :backupext,
  'bdir' => :backupdir,
  'sbr' => :showbreak,
  'top' => :tildeop,
  'wb' => :writebackup,
  'sh' => :shell,
  'ar' => :autoread,
  'hid' => :hidden,
  'ul' => :undolevels,
  'nuw' => :numberwidth,
  'fp' => :formatprg,
  'ps' => :paste,
  'pt' => :pastetoggle,
  'wig' => :wildignore,
  'eol' => :endofline,
  'inf' => :infercase,
  'ep' => :equalprg,
  'bri' => :breakindent,
  'fixeol' => :fixendofline,
  'shcf' => :shellcmdflag,
  'gfm' => :grepformat,
  'bo' => :belloff,
  'scl' => :signcolumn,
  'ut' => :updatetime,
  'shm' => :shortmess,
  'cb' => :clipboard,
  'bg' => :background,
  'swb' => :switchbuf,
  'ead' => :eadirection,
  'cot' => :completeopt,
  'to' => :timeout,
  'tm' => :timeoutlen,
  'isf' => :isfname,
  'isi' => :isident,
  'ws' => :wrapscan,
  'ch' => :cmdheight,
  'isk' => :iskeyword,
  'mps' => :matchpairs,
  'fo' => :formatoptions,
  'com' => :comments,
  'cms' => :commentstring,
  'pa' => :path,
  'wmh' => :winminheight,
  'wh' => :winheight,
  'wiw' => :winwidth,
  'wmw' => :winminwidth,
  'smc' => :synmaxcol,
  'rdt' => :redrawtime,
  'cin' => :cindent,
  'cino' => :cinoptions,
  'cinw' => :cinwords,
  'lw' => :lispwords,
  'sts' => :softtabstop,
  'sta' => :smarttab,
  'wm' => :wrapmargin,
  'sel' => :selection,
  'slm' => :selectmode,
  'cole' => :conceallevel,
  'cocu' => :concealcursor,
  'brk' => :breakat,
  'mat' => :matchtime,
  'cwh' => :cmdwinheight,
  'swf' => :swapfile,
  'dir' => :directory,
  'uc' => :updatecount,
  'vdir' => :viewdir,
  'vop' => :viewoptions,
  'rtp' => :runtimepath,
  'cd' => :cdpath,
  'def' => :define,
  'inc' => :include,
  'ssop' => :sessionoptions,
  'cpo' => :cpoptions,
  'dy' => :display,
  'fcs' => :fillchars,
  'tal' => :tabline,
  'vbs' => :verbose,
  'scb' => :scrollbind,
  'crb' => :cursorbind,
  'sp' => :shellpipe,
  'srr' => :shellredir,
  'ssl' => :shellslash,
  'cink' => :cinkeys,
  'hh' => :helpheight,
  'hlg' => :helplang,
  'tc' => :tagcase,
  'tgst' => :tagstack,
  'mh' => :mousehide,
  'mousem' => :mousemodel,
  'mouset' => :mousetime,
  'imi' => :iminsert,
  'ims' => :imsearch,
  'lmap' => :langmap,
  're' => :regexpengine,
  'tr' => :tagrelative,
  'wc' => :wildchar,
  'wcm' => :wildcharm,
  'wim' => :wildmode,
  'pvh' => :previewheight,
  'js' => :joinspaces,
  'wfh' => :winfixheight,
  'wfw' => :winfixwidth,
  'cst' => :cscopetag,
  'csprg' => :cscopeprg,
  'csto' => :cscopetagorder,
  'vi' => :viminfo,
  'cpt' => :complete,
  'dict' => :dictionary,
  'tsr' => :thesaurus,
  'gd' => :gdefault,
  'ex' => :exrc,
  'wop' => :wildoptions,
  'cmp' => :casemap,
  'qe' => :quoteescape,
  'flp' => :formatlistpat,
  'kmp' => :keymap,
  'wak' => :winaltkeys,
  'ofu' => :omnifunc,
  'opfunc' => :operatorfunc,
  'tfu' => :tagfunc,
  'fex' => :formatexpr,
  'inde' => :indentexpr,
  'indk' => :indentkeys,
  'fde' => :foldexpr,
  'fdt' => :foldtext,
  'fml' => :foldminlines,
  'fdn' => :foldnestmax,
  'eb' => :errorbells,
  'vb' => :visualbell,
  'tf' => :ttyfast,
  'tgc' => :termguicolors,
  'tenc' => :termencoding,
  'spc' => :spellcapcheck,
  'spf' => :spellfile,
  'sps' => :spellsuggest,
  'dg' => :digraph,
  'ri' => :revins,
  'rl' => :rightleft,
  'rlc' => :rightleftcmd,
  'ffs' => :fileformats,
  'fic' => :fileignorecase,
  'mm' => :maxmem,
  'mmp' => :maxmempattern,
  'mmt' => :maxmemtot,
  'mmd' => :maxmapdepth,
  'mfd' => :maxfuncdepth,
  'wa' => :writeany,
  'wd' => :writedelay,
  'awa' => :autowriteall,
  'fs' => :fsync,
  'deco' => :delcombine,
  'emo' => :emoji,
  'tbs' => :tagbsearch,
  'ss' => :sidescroll,
  'pw' => :pumwidth,
  'spk' => :splitkeep,
  'su' => :suffixes,
  'sua' => :suffixesadd,
  'ft' => :filetype,
  'ei' => :eventignore,
  'wic' => :wildignorecase,
  'lpl' => :loadplugins,
  'tpm' => :tabpagemax,
  'pheader' => :printheader,
  'popt' => :printoptions,
  'pfn' => :printfont,
  'penc' => :printencoding,
  'pexpr' => :printexpr,
  'csre' => :cscoperelative,
  'cspc' => :cscopepathcomp,
  'csqf' => :cscopequickfix,
  'csverb' => :cscopeverbose,
  'isp' => :isprint,
  'hf' => :helpfile,
  'lm' => :langmenu,
  'qftf' => :quickfixtextfunc,
  'icm' => :inccommand,
  'winbl' => :winblend,
  'cinsd' => :cinscopedecls,
  'rs' => :restorescreen,
  'lop' => :lispoptions,
  'vif' => :viminfofile,
}.freeze
KNOWN =
(DEFAULTS.keys + ALIASES.values).uniq.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



508
509
510
511
# File 'lib/rvim/settings.rb', line 508

def initialize
  @options = DEFAULTS.dup
  @editor = nil
end

Instance Attribute Details

#editorObject

Returns the value of attribute editor.



513
514
515
# File 'lib/rvim/settings.rb', line 513

def editor
  @editor
end

Instance Method Details

#get(name, buffer: :current) ⇒ Object



515
516
517
518
519
520
521
522
523
# File 'lib/rvim/settings.rb', line 515

def get(name, buffer: :current)
  key = normalize(name)
  buf = buffer == :current ? @editor&.current_buffer : buffer
  if buf && buf.respond_to?(:local_settings) && buf.local_settings.key?(key)
    buf.local_settings[key]
  else
    @options[key]
  end
end

#known?(name) ⇒ Boolean

Returns:

  • (Boolean)


540
541
542
# File 'lib/rvim/settings.rb', line 540

def known?(name)
  KNOWN.include?(normalize(name))
end

#normalize(name) ⇒ Object



544
545
546
547
# File 'lib/rvim/settings.rb', line 544

def normalize(name)
  sym = name.to_s
  ALIASES[sym] || sym.to_sym
end

#set(name, value, buffer: nil) ⇒ Object



525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/rvim/settings.rb', line 525

def set(name, value, buffer: nil)
  key = normalize(name)
  if buffer
    buffer.local_settings[key] = value
  else
    @options[key] = value
  end
  # Notify the Lua runtime so package.path tracks &runtimepath edits
  # made after init time (e.g. vim.opt.rtp:prepend in init.lua, :packadd).
  if key == :runtimepath && @editor && @editor.respond_to?(:lua_loader_refresh)
    @editor.lua_loader_refresh
  end
  key
end