Hi guys,
I've got two patches and three questions:
First, the patches. The first fixes editing of length 0 files, the second fixes
compilation on OpenBSD. Since _BSD_SOURCE was already present in other files
belonging to vis, I figured adding it to vis.c as well poses no harm.
The first question is about line numbers. Would a patch adding display of line
numbers be accepted, or is that considered unnecessary cruft? I find it makes
jumping through a file a bit easier.
My other question is about piping (part of) the buffer to an external command,
such as fmt. Is someone already working on that or is that something I could
start looking into? Piping would also provide a (stop-gap) solution for :s, for
example by piping to sed or some other stream editor.
I'm also seeing quite a bit of display corruption when opening large syntax
highlighted files, such as window.c and scrolling around the file for a while.
Is anyone else seeing that or is it just me? I'm using tmux and st, if that
matters.
--
Gregor Best
>From 82aaaf3da2c6eb4ebe74b3d66949c11b1be64556 Mon Sep 17 00:00:00 2001
From: Gregor Best <[email protected]>
Date: Tue, 16 Sep 2014 13:24:37 +0200
Subject: [PATCH 1/2] Fix editing of files with length 0
Signed-off-by: Gregor Best <[email protected]>
---
text.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/text.c b/text.c
index 2bdfe75..9aa8b2c 100644
--- a/text.c
+++ b/text.c
@@ -663,9 +663,15 @@ Text *text_load(const char *filename) {
goto out;
// XXX: use lseek(fd, 0, SEEK_END); instead?
txt->buf.size = txt->info.st_size;
- txt->buf.data = mmap(NULL, txt->info.st_size, PROT_READ,
MAP_SHARED, txt->fd, 0);
- if (txt->buf.data == MAP_FAILED)
- goto out;
+ if (txt->buf.size == 0) {
+ txt->buf.data = NULL;
+ } else {
+ txt->buf.data = mmap(NULL, txt->info.st_size,
PROT_READ, MAP_SHARED, txt->fd, 0);
+ if (txt->buf.data == MAP_FAILED) {
+ perror("mmap");
+ goto out;
+ }
+ }
Piece *p = piece_alloc(txt);
if (!p)
--
2.1.0
>From 7a133a321da98bae3feafdf0885da422ac531cd0 Mon Sep 17 00:00:00 2001
From: Gregor Best <[email protected]>
Date: Tue, 16 Sep 2014 13:25:18 +0200
Subject: [PATCH 2/2] Fix compilation on OpenBSD
Signed-off-by: Gregor Best <[email protected]>
---
vis.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/vis.c b/vis.c
index 3a6a3a3..8cbe3dd 100644
--- a/vis.c
+++ b/vis.c
@@ -14,6 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define _POSIX_SOURCE
+/* Necessary for SIGWINCH on OpenBSD */
+#define _BSD_SOURCE
#include <locale.h>
#include <stdlib.h>
#include <unistd.h>
--
2.1.0