diff --git a/NEWS.md b/NEWS.md
index c401f63..d86c7df 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,11 @@
# ToyEd text editor project news
+## [Unreleased]
+
+### Added
+
+* Number Lines command
+
## [1.3] - 2024-01-23
### Added
diff --git a/toyed.tcl b/toyed.tcl
index 97b6679..074cfd3 100644
--- a/toyed.tcl
+++ b/toyed.tcl
@@ -1,7 +1,7 @@
#!/usr/bin/env tclsh
#
# ToyEd: a toy text editor for educational purposes in Tcl/Tk.
-# Copyright 2022, 2023 Felix Pleșoianu
+# Copyright 2022, 2023, 2024 Felix Pleșoianu
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# 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" \
-command {tk_util::select_all .editor; break}
$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
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 command -label "Prefix lines..." -command prefix_lines \
-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
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 \
-command {toggle_lines .editor}
$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}
$m add command -label "Smaller font" -under 0 -accel "Ctrl -" \
-command {font_size decr .editor}
@@ -316,6 +318,7 @@ bind .editor {lower_case; break}
bind .editor {title_case; break}
bind .editor upper_case
bind .editor prefix_lines
+bind .editor {number_lines; break}
bind . {font_size::increase .editor}
bind . {font_size::decrease .editor}
@@ -674,6 +677,23 @@ proc prefix_lines {} {
.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 {
if {[$widget cget -linemap]} {
$widget configure -linemap 0