[prev in list] [next in list] [prev in thread] [next in thread]
List: openbsd-tech
Subject: [patch] to make mg's dired more ``emacs'' like
From: Loganaden Velvindron <loganaden () gmail ! com>
Date: 2010-03-26 5:16:03
Message-ID: 4d0ffae1003252216j65678ee0i9b9d1761598ea859 () mail ! gmail ! com
[Download RAW message or body]
Greetings,
It's a small patch that aligns the cursor
on the first filename on in dired.c
If the directory is empty, it positions the cursor on
the ``..''.
If the directory can't be read (due to permission issues),
it prints permission denied.
Lastly, the patch for file.c prevents readin from resetting
the cursor position when the buffer is a directory.
Please send me feedback on how I can improve, if you can spare some
time to review it.
Index: dired.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.45
diff -u -r1.45 dired.c
--- dired.c 4 Jun 2009 23:39:37 -0000 1.45
+++ dired.c 26 Mar 2010 04:55:43 -0000
@@ -592,8 +592,15 @@
struct buffer *bp;
FILE *dirpipe;
char line[256];
- int len, ret;
-
+ int len, ret, ia, cpos, counter, warp;
+ char *index;
+ counter = 0;
+ warp = 3;
+ if ((fopen(dname,"r")) == NULL) {
+ if (errno == EACCES)
+ ewprintf("Permission denied");
+ return (NULL);
+ }
if ((dname = adjustname(dname, FALSE)) == NULL) {
ewprintf("Bad directory name");
return (NULL);
@@ -624,6 +631,15 @@
while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
line[strcspn(line, "\n")] = '\0'; /* remove ^J */
(void) addline(bp, line);
+ counter++;
+ }
+ if ((index=strrchr(line,' ')) != NULL) {
+ cpos=line-index;
+ if (cpos < 0) {
+ cpos *= -1;
+ cpos += 1;
+ bp->b_doto = cpos;
+ }
}
if (pclose(dirpipe) == -1) {
ewprintf("Problem closing pipe to ls : %s",
@@ -631,6 +647,10 @@
return (NULL);
}
bp->b_dotp = bfirstlp(bp);
+ if (counter < 4)
+ warp = 2;
+ for (ia=0 ; ia < warp ; ia++)
+ bp->b_dotp = lforw(bp->b_dotp);
(void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname));
(void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd));
if ((bp->b_modes[1] = name_mode("dired")) == NULL) {
Index: file.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/file.c,v
retrieving revision 1.71
diff -u -r1.71 file.c
--- file.c 4 Jun 2009 23:39:37 -0000 1.71
+++ file.c 26 Mar 2010 04:56:24 -0000
@@ -220,10 +220,12 @@
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
if (wp->w_bufp == curbp) {
- wp->w_dotp = wp->w_linep = bfirstlp(curbp);
- wp->w_doto = 0;
- wp->w_markp = NULL;
- wp->w_marko = 0;
+ if ((fisdir(fname)) != TRUE) {
+ wp->w_dotp = wp->w_linep = bfirstlp(curbp);
+ wp->w_doto = 0;
+ wp->w_markp = NULL;
+ wp->w_marko = 0;
+ }
}
}
Thanks
//Logan
C-x-C-c
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic