Skip to content

ed: save space in editor buffer #938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

mknos
Copy link
Contributor

@mknos mknos commented Jan 31, 2025

  • The substitution s/\z/NEW/ produced the unwanted outcome of $lines[$x] containing two lines of text
  • Address this by not including trailing newlines in the editor buffer anymore
  • Introduce helper function get_terminated_line() which adds the newline
  • Now s/\z/NEW/ is interpreted the same as s/$/NEW/, i.e. append NEW to end of line
  • Bump version number in case of regressions
  • Removing the newlines from the editor buffer also reduces memory usage, but that is not the main intent of this patch

Test...

  1. Null command
*1
#include <stdio.h>
  1. List command w/lineno
*1,2ln
1	#include <stdio.h>$
2	#include <stdlib.h>$
  1. Print command
*1p
#include <stdio.h>
  1. Join command
*1,2j    
*1
#include <stdio.h>#include <stdlib.h>
  1. Transpose (copy) command
*4n
4	int
*4t0
*1,2n
1	int
2	#include <stdio.h>#include <stdlib.h>
  1. Move command
*1,2m$   
*$-2,$n 
42	} // ddd?s
43	int
44	#include <stdio.h>#include <stdlib.h>
  1. Substitute command
*$
#include <stdio.h>#include <stdlib.h>
*s/include/exclude/g
*.
#exclude <stdio.h>#exclude <stdlib.h>
  1. Delete command
*$d
*$=
43
*.
int
  1. Insert command
*0i    
start of buffer
.
*1n 
1	start of buffer
  1. Append command
*1a    
2ND LINE!!!!!
.
*1,2n
1	start of buffer
2	2ND LINE!!!!!
  1. Change command
*1,2c
BEGIN buffer     
second line 
.
*1,2n
1	BEGIN buffer
2	second line
  1. Undo command
*u
*1,2n
1	start of buffer
2	2ND LINE!!!!!
  1. EDIT command
*E a.s
790
*1,3n
1		.arch armv6
2		.eabi_attribute 28, 1
3		.eabi_attribute 20, 1
  1. Filename command
*f 
a.s
  1. Read command (linux ifconfig prints and extra empty line)
*0r !ifconfig lo 
387
*.=
9
  1. Write command
*1,15w !cat -n 
     1	lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
     2	        inet 127.0.0.1  netmask 255.0.0.0
     3	        inet6 ::1  prefixlen 128  scopeid 0x10<host>
     4	        loop  txqueuelen 1000  (Local Loopback)
     5	        RX packets 30  bytes 2892 (2.8 KiB)
     6	        RX errors 0  dropped 0  overruns 0  frame 0
     7	        TX packets 30  bytes 2892 (2.8 KiB)
     8	        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
     9	
    10		.arch armv6
    11		.eabi_attribute 28, 1
    12		.eabi_attribute 20, 1
    13		.eabi_attribute 21, 1
    14		.eabi_attribute 23, 3
    15		.eabi_attribute 24, 1
524
  1. Regex prefix + Number command
*/main/n 
32		.global	main
  1. Repeat search with empty regex
*//
	.type	main, %function
  1. Mark command (current addr saved as x)
*.kx
*$
	.section	.note.GNU-stack,"",%progbits
*'xs/function/F_U_N_K_T_O_W_N/
*n
37		.type	main, %F_U_N_K_T_O_W_N
  1. HelpMode command
*-1000000000000000000000
?
*H
invalid address
*-----------
	.ascii	"yo\000"
*yo
?
unknown command

* The substitution s/\z/NEW/ produced the unwanted outcome of $lines[$x] containing two lines of text
* Address this by not including trailing newlines in the editor buffer anymore
* Introduce helper function get_terminated_line() which adds the newline
* Now s/\z/NEW/ is interpreted the same as s/$/NEW/, i.e. append NEW to end of line
* Bump version number in case of regressions
* Removing the newlines from the editor buffer also reduces memory usage, but that is not the main intent of this patch
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: ed The ed program labels Jan 31, 2025
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:09 — with GitHub Actions Inactive
@mknos mknos temporarily deployed to automated_testing January 31, 2025 09:10 — with GitHub Actions Inactive
@coveralls
Copy link

coveralls commented Jan 31, 2025

Pull Request Test Coverage Report for Build 13069671346

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.7%) to 73.389%

Totals Coverage Status
Change from base Build 13054078573: -0.7%
Covered Lines: 353
Relevant Lines: 481

💛 - Coveralls

@briandfoy briandfoy self-assigned this Jan 31, 2025
@briandfoy
Copy link
Owner

I don't know enough about ed, but is this how the other versions work? Specifically, if I use \z to anchor, the newline should still be there?

If tis patch makes it work like the other ed's, I'm fine with this. Typically you have compatibility notes in the PR, but not this time.

@briandfoy briandfoy added the Status: needs feedback requestor or community feedback needed to go on label Jan 31, 2025
@mknos
Copy link
Contributor Author

mknos commented Feb 4, 2025

The \z match includes the newline, which was problematic because text could be substituted after the newline, which is supposed to terminate the line string.
Using \z is not compatible with other versions of ed because it is a perl-regex-ism.
For now this patch will avoid the problem of incorrectly splitting a line.
For greater compatibility I can make another patch to interpret \z as "z" and \Z as "Z" (similar to how "\n" is currently handled).

@briandfoy
Copy link
Owner

Ah, I get it now. Thanks for the clarification.

@briandfoy briandfoy merged commit 2e823de into briandfoy:master Feb 4, 2025
21 of 23 checks passed
@briandfoy briandfoy added Status: accepted The fix is accepted Status: released there is a new release with this fix and removed Priority: low get to this whenever Status: needs feedback requestor or community feedback needed to go on Status: accepted The fix is accepted labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: ed The ed program Status: released there is a new release with this fix Type: enhancement improve a feature that already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants