Skip to content

Commit

Permalink
support different multiple comments for different langs
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Oct 20, 2023
1 parent 5adcf7c commit 3219110
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 30 deletions.
3 changes: 1 addition & 2 deletions autocomplete.v
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ fn (ved &Ved) draw_autocomplete_window() {
return
}

ved.gg.draw_rect_filled(x, y, width, height, gx.white)

if ved.autocomplete_info.vars.len == 0 {
return
}
ved.gg.draw_rect_filled(x, y, width, height, gx.white)
// ved.gg.draw_text(x + 10, y + 30, 'AUTOCOMPLETE', txt_cfg)

// for i, var in ved.autocomplete_info.vars {
Expand Down
25 changes: 25 additions & 0 deletions hl.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by a GPL license
// that can be found in the LICENSE file.
module main

struct Mcomment {
start1 rune
start2 rune
end1 rune
end2 rune
}

fn get_mcomment_by_ext(ext string) Mcomment {
return match ext {
//'v', 'go', 'c', 'cpp' {
// Mcomment{`/`, `*`, `*`, `/`}
//}
'.html' {
Mcomment{`<`, `!`, `-`, `>`}
}
else {
Mcomment{`/`, `*`, `*`, `/`}
}
}
}
11 changes: 8 additions & 3 deletions timer.v
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn (mut timer Timer) key_down(key gg.KeyCode, super bool) {

fn lock_screen() {
$if macos {
os.system('pmset displaysleepnow')
// os.system('pmset displaysleepnow')
}
}

Expand All @@ -207,10 +207,15 @@ fn (ved &Ved) insert_task() ! {
mut f := os.open_append(tasks_path)!
task_name := ved.cur_task.limit(max_task_len) +
strings.repeat(` `, max_task_len - ved.cur_task.len)
mins := ved.task_minutes().str() + 'm'
mut mins := ved.task_minutes().str() + 'm'
too_long := ved.task_minutes() > 60 * 8
if too_long {
// More than 8 hours, probably forgot to end, insert only one hour
mins = '60m'
}
mins_pad := strings.repeat(` `, 4 - mins.len)
now := time.now()
if start_time.day == now.day && start_time.month == now.month {
if (start_time.day == now.day && start_time.month == now.month) || too_long {
// Single day entry
f.writeln('| ${task_name} | ${mins} ${mins_pad} | ' + start_time.format() + ' | ' +
time.now().hhmm() + ' |')!
Expand Down
65 changes: 40 additions & 25 deletions ved.v
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ mut:

// For syntax highlighting
enum ChunkKind {
a_string = 1
a_string = 1
a_comment = 2
a_key = 3
a_lit = 4
a_key = 3
a_lit = 4
}

enum EditorMode {
normal = 0
insert = 1
query = 2
visual = 3
timer = 4
normal = 0
insert = 1
query = 2
visual = 3
timer = 4
autocomplete = 5
}

Expand Down Expand Up @@ -123,36 +123,30 @@ Options:
)

const (
fpath = os.resource_abs_path('RobotoMono-Regular.ttf')
fpath = os.resource_abs_path('RobotoMono-Regular.ttf')
args = os.args.clone()
is_window = '-window' in args
)

[console]
fn main() {
args := os.args.clone()
if '-h' in args || '--help' in args {
println(help_text)
return
}
if !os.is_dir(settings_dir) {
os.mkdir(settings_dir) or { panic(err) }
}
mut nr_splits := 3
is_window := '-window' in args
if '-two_splits' in args {
nr_splits = 2
}
if is_window || '-laptop' in args {
nr_splits = 1
}
mut size := gg.screen_size()
if size.width == 0 || size.height == 0 {
size = $if small_window ? { gg.Size{770, 480} } $else { gg.Size{2560, 1480} }
size = $if small_window ? { gg.Size{770, 480} } $else { gg.Size{2560, 1440} }
}
println('size=${size}')
mut ved := &Ved{
win_width: size.width
win_height: size.height
nr_splits: nr_splits
splits_per_workspace: nr_splits
// nr_splits: nr_splits
// splits_per_workspace: nr_splits
cur_split: 0
mode: .normal
view: 0
Expand All @@ -165,6 +159,10 @@ fn main() {
ved.cfg.set_settings(config_path)
ved.cfg.reload_config()

nr_splits := ved.get_nr_splits_from_screen_size(size.width, size.height)
ved.nr_splits = nr_splits
ved.splits_per_workspace = nr_splits

println('height=${size.height}')

ved.load_syntaxes()
Expand All @@ -186,7 +184,7 @@ fn main() {
font_path: fpath
ui_mode: true
)
println('FULL SCREEN=${!is_window}')
println('1FULL SCREEN=${!is_window}')
ved.timer = new_timer(ved.gg)
ved.load_all_tasks()
// TODO linux and windows
Expand Down Expand Up @@ -637,6 +635,7 @@ fn (mut ved Ved) add_chunk(typ ChunkKind, start int, end int) {
}

fn (mut ved Ved) draw_text_line(x int, y int, line string) {
mcomment := get_mcomment_by_ext(os.file_ext(ved.view.path))
// Red/green test hack
/*
if line.contains('[32m') && line.contains('PASS') {
Expand All @@ -663,15 +662,15 @@ fn (mut ved Ved) draw_text_line(x int, y int, line string) {
}
// Comment /*
// (unless it's /* line */ which is a single line)
if i > 0 && line[i - 1] == `/` && line[i] == `*` && !(line[line.len - 2] == `*`
&& line[line.len - 1] == `/`) {
if i > 0 && line[i - 1] == mcomment.start1 && line[i] == mcomment.start2
&& !(line[line.len - 2] == mcomment.end1 && line[line.len - 1] == mcomment.end2) {
// All after /* is a comment
ved.add_chunk(.a_comment, start, line.len)
ved.is_ml_comment = true
break
}
// End of /**/
if i > 0 && line[i - 1] == `*` && line[i] == `/` {
if i > 0 && line[i - 1] == mcomment.end1 && line[i] == mcomment.end2 {
// All before */ is still a comment
ved.add_chunk(.a_comment, 0, start + 1)
ved.is_ml_comment = false
Expand Down Expand Up @@ -1975,3 +1974,19 @@ fn (mut ved Ved) increase_font(delta int) {
fn filter_ascii_colors(s string) string {
return s.replace_each(['[22m', '', '[35m', '', '[39m', '', '[1m', '', '[31m', ''])
}

fn (ved &Ved) get_nr_splits_from_screen_size(width int, height int) int {
mut nr_splits := 3
if '-two_splits' in args {
nr_splits = 2
}
if is_window || '-laptop' in args {
nr_splits = 1
}
max_split_width := ved.cfg.char_width * 110
println('MAX=${max_split_width}')
if false {
exit(1)
}
return nr_splits
}

0 comments on commit 3219110

Please sign in to comment.