[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nano-devel
Subject:    [Nano-devel] [PATCH V2] possible new feature: a tab command to define what the Tab key produces
From:       Benno Schulenberg <bensberg () telfort ! nl>
Date:       2018-10-30 15:51:33
Message-ID: 20181030155133.17147-1-bensberg () telfort ! nl
[Download RAW message or body]

V2: Indenting and unindenting a marked region should work too: it must
add and remove the exact contents of the specified tab string.  But this
also means that, when a tab string is specfied, the unindenting is no
longer flexible: it will no longer see tabsize spaces as equivalent to
a tab, nor the other way around.

The 'tab' command is syntax-specific and should be followed by a string
containing the character(s) that a single press of the <Tab> key should
produce -- most likely a single TAB or a small bunch of spaces, but any
string is allowed.  This overrides the 'tabstospaces' option/toggle.

This addresses https://savannah.gnu.org/bugs/?53661,
and addresses https://savannah.gnu.org/bugs/?54760,
and addresses part of https://savannah.gnu.org/bugs/?54775.
---
 src/nano.h   |  2 ++
 src/rcfile.c |  3 +++
 src/text.c   | 24 ++++++++++++++++++++++++
 3 files changed, 29 insertions(+)

diff --git a/src/nano.h b/src/nano.h
index 3007881d..b53d4e86 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -227,6 +227,8 @@ typedef struct syntaxtype {
 		/* The list of libmagic results that this syntax applies to. */
 	char *linter;
 		/* The command with which to lint this type of file. */
+	char *tab;
+		/* What the Tab key should produce; NULL for default behavior. */
 #ifdef ENABLE_COMMENT
 	char *comment;
 		/* The line comment prefix (and postfix) for this type of file. */
diff --git a/src/rcfile.c b/src/rcfile.c
index d8a2d1fe..6c434a96 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -300,6 +300,7 @@ void parse_syntax(char *ptr)
 	live_syntax->headers = NULL;
 	live_syntax->magics = NULL;
 	live_syntax->linter = NULL;
+	live_syntax->tab = NULL;
 #ifdef ENABLE_COMMENT
 	live_syntax->comment = mallocstrcpy(NULL, GENERAL_COMMENT_CHARACTER);
 #endif
@@ -993,6 +994,8 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
 			parse_colors(ptr, NANO_REG_EXTENDED | REG_ICASE);
 		else if (strcasecmp(keyword, "linter") == 0)
 			pick_up_name("linter", ptr, &live_syntax->linter);
+		else if (strcasecmp(keyword, "tab") == 0)
+			pick_up_name("tab", ptr, &live_syntax->tab);
 		else if (syntax_only && (strcasecmp(keyword, "set") == 0 ||
 								strcasecmp(keyword, "unset") == 0 ||
 								strcasecmp(keyword, "bind") == 0 ||
diff --git a/src/text.c b/src/text.c
index 8302c7dd..a89180f6 100644
--- a/src/text.c
+++ b/src/text.c
@@ -267,6 +267,11 @@ void do_cut_next_word(void)
  * of spaces that a tab would normally take up. */
 void do_tab(void)
 {
+#ifdef ENABLE_COLOR
+	if (openfile->syntax && openfile->syntax->tab)
+		do_output(openfile->syntax->tab, strlen(openfile->syntax->tab), TRUE);
+	else
+#endif
 #ifndef NANO_TINY
 	if (ISSET(TABS_TO_SPACES)) {
 		char *spaces = charalloc(tabsize + 1);
@@ -332,6 +337,11 @@ void do_indent(void)
 	indentation = charalloc(tabsize + 1);
 
 	/* Set the indentation to either a bunch of spaces or a single tab. */
+#ifdef ENABLE_COLOR
+	if (openfile->syntax && openfile->syntax->tab)
+		indentation = mallocstrcpy(indentation, openfile->syntax->tab);
+	else
+#endif
 	if (ISSET(TABS_TO_SPACES)) {
 		charset(indentation, ' ', tabsize);
 		indentation[tabsize] = '\0';
@@ -364,6 +374,20 @@ size_t length_of_white(const char *text)
 {
 	size_t bytes_of_white = 0;
 
+#ifdef ENABLE_COLOR
+	if (openfile->syntax && openfile->syntax->tab) {
+		size_t thelength = strlen(openfile->syntax->tab);
+
+		while (bytes_of_white < thelength) {
+			if (text[bytes_of_white] != openfile->syntax->tab[bytes_of_white])
+				return 0;
+			bytes_of_white++;
+		}
+
+		return thelength;
+	}
+#endif
+
 	while (TRUE) {
 		if (*text == '\t')
 			return ++bytes_of_white;
-- 
2.19.1


_______________________________________________
Nano-devel mailing list
Nano-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/nano-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic