Coder Social home page Coder Social logo

vim9 lambda execute failed about vim HOT 5 CLOSED

yu3s avatar yu3s commented on May 27, 2024
vim9 lambda execute failed

from vim.

Comments (5)

chrisbra avatar chrisbra commented on May 27, 2024

are you looking for mapnew() ?

from vim.

yu3s avatar yu3s commented on May 27, 2024

are you looking for mapnew() ?

it works, thanks.
btw, the function I need are as follows

def Hiset(group: string, fg: list<string>, bg: list<string>, ...strlist: list<string>)
	var attr: dict<bool>
	var val: dict<bool> = strlist->empty() ? {'NONE': v:true} : 
		strlist[0]->split(',')->map((_, v) => {
			attr[v] = v:true
			return attr
		})[0]

	hlset([{
		name: group,
		guifg: fg[0],	guibg: bg[0],	gui: val,
		ctermfg: fg[1],	ctermbg: bg[1], cterm: val,
	}])
enddef

Hiset('ErrorMsg', palette.red, palette.none, 'bold,underline')

from vim.

chrisbra avatar chrisbra commented on May 27, 2024

BTW: now you can also use the foreach() expression.

from vim.

yu3s avatar yu3s commented on May 27, 2024

BTW: now you can also use the foreach() expression.

thanks, I'm just reporting the issue I found.
I want to implement a function that return a dict variable using vim9 lambda, foreach expression does not apply to my needs

from vim.

yu3s avatar yu3s commented on May 27, 2024

BTW: now you can also use the foreach() expression.

Already used

vim9script noclear

highlight default JumpFocus			guifg=#958c6a
highlight default JumpMain			guifg=#f2119c gui=bold cterm=bold

const limit = 200
var table: list<dict<any>>

def Init()
	var name: string
	var str: list<string> = 'fjdklshgaewiomc'->split('\zs')
	var len: number = str->len()

	for idx in range(limit)
		table->add({'name': str[idx / len] .. str[idx % len]})

		name = table[idx]['name']
		table[idx][name] = popup_create(name, {hidden: true, wrap: false, tabpage: -1, highlight: "JumpMain"})
	endfor
enddef

def Show(lnum: number, end: number)
	var len: number
	var ch: string
	var id: number
	var screen_pos: dict<any>
	var input: string

	id = matchaddpos("JumpFocus", range(lnum, end))
	defer matchdelete(id)
	redraw

	ch = nr2char(getchar())
	len = foreach(matchbufline(bufnr(), '\<\k\+\>', lnum, end)
		->filter((_, v) => v.text =~? ch),
		"table[v:key]['pos'] = v:val")->len()

	if len == 0
		return
	elseif len >= limit
		len = limit
	endif

	for idx in range(len)
		screen_pos = screenpos(winnr(), table[idx]['pos']['lnum'], table[idx]['pos']['byteidx'] + 1)

		popup_move(table[idx][table[idx].name], {line: screen_pos.row, col: screen_pos.curscol})
		popup_show(table[idx][table[idx].name])
	endfor
	redraw

	for _ in range(2)
		input ..= nr2char(getchar())

		if input !~# '\l'
			break
		endif
	endfor

	for idx in range(len)
		if table[idx]->has_key(input)
			cursor(table[idx]['pos']['lnum'], table[idx]['pos']['byteidx'] + 1)
		endif

		popup_hide(table[idx][table[idx].name])
	endfor
enddef

export def Jump()
	var conceal: number

	if table->empty()
		Init()
	endif

	conceal = &conceallevel
	&conceallevel = 0
	Show(line('w0'), line('w$'))
	&conceallevel = conceal
enddef

from vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.