Add Number Lines command
This commit is contained in:
parent
52923fc34f
commit
afbd317453
6
NEWS.md
6
NEWS.md
|
@ -1,5 +1,11 @@
|
||||||
# ToyEd text editor project news
|
# ToyEd text editor project news
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
* Number Lines command
|
||||||
|
|
||||||
## [1.3] - 2024-01-23
|
## [1.3] - 2024-01-23
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
26
toyed.tcl
26
toyed.tcl
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env tclsh
|
#!/usr/bin/env tclsh
|
||||||
#
|
#
|
||||||
# ToyEd: a toy text editor for educational purposes in Tcl/Tk.
|
# ToyEd: a toy text editor for educational purposes in Tcl/Tk.
|
||||||
# Copyright 2022, 2023 Felix Pleșoianu <https://felix.plesoianu.ro/>
|
# Copyright 2022, 2023, 2024 Felix Pleșoianu <https://felix.plesoianu.ro/>
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -234,7 +234,7 @@ $m add separator
|
||||||
$m add command -label "Select all" -under 7 -accel "Ctrl-A" \
|
$m add command -label "Select all" -under 7 -accel "Ctrl-A" \
|
||||||
-command {tk_util::select_all .editor; break}
|
-command {tk_util::select_all .editor; break}
|
||||||
$m add command -label "Find..." -command do_find -under 0 -accel "Ctrl-F"
|
$m add command -label "Find..." -command do_find -under 0 -accel "Ctrl-F"
|
||||||
$m add command -label "Again" -command find_again -under 1 -accel "Ctrl-G"
|
$m add command -label "Next" -command find_again -under 0 -accel "Ctrl-G"
|
||||||
.menubar add cascade -menu .menubar.edit -label "Edit" -underline 0
|
.menubar add cascade -menu .menubar.edit -label "Edit" -underline 0
|
||||||
|
|
||||||
set m [menu .menubar.mFormat]
|
set m [menu .menubar.mFormat]
|
||||||
|
@ -248,6 +248,8 @@ $m add command -label "Upper case" -command upper_case -under 0 -accel "Alt-U"
|
||||||
$m add separator
|
$m add separator
|
||||||
$m add command -label "Prefix lines..." -command prefix_lines \
|
$m add command -label "Prefix lines..." -command prefix_lines \
|
||||||
-under 0 -accel "Alt-P"
|
-under 0 -accel "Alt-P"
|
||||||
|
$m add command -label "Number lines" -command number_lines \
|
||||||
|
-under 0 -accel "Alt-N"
|
||||||
.menubar add cascade -menu .menubar.mFormat -label "Format" -underline 3
|
.menubar add cascade -menu .menubar.mFormat -label "Format" -underline 3
|
||||||
|
|
||||||
set m [menu .menubar.view]
|
set m [menu .menubar.view]
|
||||||
|
@ -256,7 +258,7 @@ $m add checkbutton -label "Word wrap" -under 0 -var _word_wrap \
|
||||||
$m add checkbutton -label "Line numbers" -under 0 -var _line_nums \
|
$m add checkbutton -label "Line numbers" -under 0 -var _line_nums \
|
||||||
-command {toggle_lines .editor}
|
-command {toggle_lines .editor}
|
||||||
$m add separator
|
$m add separator
|
||||||
$m add command -label "Bigger font" -under 0 -accel "Ctrl +" \
|
$m add command -label "Bigger font" -under 0 -accel "Ctrl-+" \
|
||||||
-command {font_size incr .editor}
|
-command {font_size incr .editor}
|
||||||
$m add command -label "Smaller font" -under 0 -accel "Ctrl -" \
|
$m add command -label "Smaller font" -under 0 -accel "Ctrl -" \
|
||||||
-command {font_size decr .editor}
|
-command {font_size decr .editor}
|
||||||
|
@ -316,6 +318,7 @@ bind .editor <Alt-l> {lower_case; break}
|
||||||
bind .editor <Alt-t> {title_case; break}
|
bind .editor <Alt-t> {title_case; break}
|
||||||
bind .editor <Alt-u> upper_case
|
bind .editor <Alt-u> upper_case
|
||||||
bind .editor <Alt-p> prefix_lines
|
bind .editor <Alt-p> prefix_lines
|
||||||
|
bind .editor <Alt-n> {number_lines; break}
|
||||||
|
|
||||||
bind . <Control-equal> {font_size::increase .editor}
|
bind . <Control-equal> {font_size::increase .editor}
|
||||||
bind . <Control-minus> {font_size::decrease .editor}
|
bind . <Control-minus> {font_size::decrease .editor}
|
||||||
|
@ -674,6 +677,23 @@ proc prefix_lines {} {
|
||||||
.editor replace sel.first sel.last [join $result "\n"]
|
.editor replace sel.first sel.last [join $result "\n"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc number_lines {} {
|
||||||
|
global status
|
||||||
|
set sel [tk_util::text_selection .editor]
|
||||||
|
if {$sel eq ""} {
|
||||||
|
set status "Nothing selected."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
set lines [split $sel "\n"]
|
||||||
|
set result [list]
|
||||||
|
set n 0
|
||||||
|
foreach l $lines {
|
||||||
|
incr n
|
||||||
|
lappend result "$n. $l"
|
||||||
|
}
|
||||||
|
.editor replace sel.first sel.last [join $result "\n"]
|
||||||
|
}
|
||||||
|
|
||||||
proc toggle_lines widget {
|
proc toggle_lines widget {
|
||||||
if {[$widget cget -linemap]} {
|
if {[$widget cget -linemap]} {
|
||||||
$widget configure -linemap 0
|
$widget configure -linemap 0
|
||||||
|
|
Loading…
Reference in New Issue