Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
f83bebed
Commit
f83bebed
authored
5 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Indent line when pressing ENTER between braces
parent
bfed7386
feature/match-parens
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/text.c
+32
-14
src/text.c
with
32 additions
and
14 deletions
+32
-14
src/text.c
View file @
f83bebed
...
@@ -96,6 +96,20 @@ void do_tab(void)
...
@@ -96,6 +96,20 @@ void do_tab(void)
do_output
((
char
*
)
"
\t
"
,
1
,
TRUE
);
do_output
((
char
*
)
"
\t
"
,
1
,
TRUE
);
}
}
size_t
tab_char_length
(
void
)
{
return
ISSET
(
TABS_TO_SPACES
)
?
tabsize
:
1
;
}
void
set_indentation
(
char
*
indentation
)
{
/* Set the indentation to either a bunch of spaces or a single tab. */
if
(
ISSET
(
TABS_TO_SPACES
))
{
charset
(
indentation
,
' '
,
tabsize
);
indentation
[
tabsize
]
=
'\0'
;
}
else
{
strcpy
(
indentation
,
"
\t
"
);
}
}
#ifndef NANO_TINY
#ifndef NANO_TINY
/* Add an indent to the given line. */
/* Add an indent to the given line. */
void
indent_a_line
(
filestruct
*
line
,
char
*
indentation
)
void
indent_a_line
(
filestruct
*
line
,
char
*
indentation
)
...
@@ -142,16 +156,8 @@ void do_indent(void)
...
@@ -142,16 +156,8 @@ void do_indent(void)
if
(
top
==
bot
->
next
)
if
(
top
==
bot
->
next
)
return
;
return
;
indentation
=
charalloc
(
tabsize
+
1
);
indentation
=
charalloc
(
tab_char_length
()
+
1
);
set_indentation
(
indentation
);
/* Set the indentation to either a bunch of spaces or a single tab. */
if
(
ISSET
(
TABS_TO_SPACES
))
{
charset
(
indentation
,
' '
,
tabsize
);
indentation
[
tabsize
]
=
'\0'
;
}
else
{
indentation
[
0
]
=
'\t'
;
indentation
[
1
]
=
'\0'
;
}
add_undo
(
INDENT
);
add_undo
(
INDENT
);
...
@@ -865,11 +871,11 @@ void do_redo(void)
...
@@ -865,11 +871,11 @@ void do_redo(void)
/* Break the current line at the cursor position. */
/* Break the current line at the cursor position. */
void
do_enter
(
void
)
void
do_enter
(
void
)
{
{
filestruct
*
newnode
=
make_new_node
(
openfile
->
current
);
size_t
extra
=
0
;
size_t
extra
=
0
;
#ifndef NANO_TINY
#ifndef NANO_TINY
filestruct
*
sampleline
=
openfile
->
current
;
filestruct
*
sampleline
=
openfile
->
current
;
bool
allblanks
=
FALSE
;
bool
allblanks
=
FALSE
;
filestruct
*
indented_line
=
NULL
;
if
(
ISSET
(
AUTOINDENT
))
{
if
(
ISSET
(
AUTOINDENT
))
{
#ifdef ENABLE_JUSTIFY
#ifdef ENABLE_JUSTIFY
...
@@ -886,8 +892,20 @@ void do_enter(void)
...
@@ -886,8 +892,20 @@ void do_enter(void)
extra
=
openfile
->
current_x
;
extra
=
openfile
->
current_x
;
else
if
(
extra
==
openfile
->
current_x
)
else
if
(
extra
==
openfile
->
current_x
)
allblanks
=
TRUE
;
allblanks
=
TRUE
;
else
if
(
openfile
->
current
->
data
[
openfile
->
current_x
-
1
]
==
'{'
&&
openfile
->
current
->
data
[
openfile
->
current_x
]
==
'}'
)
{
indented_line
=
make_new_node
(
openfile
->
current
);
indented_line
->
data
=
charalloc
(
extra
+
tab_char_length
()
+
1
);
strncpy
(
indented_line
->
data
,
sampleline
->
data
,
extra
);
set_indentation
(
indented_line
->
data
+
extra
);
splice_node
(
openfile
->
current
,
indented_line
);
}
}
}
#endif
/* NANO_TINY */
#endif
/* NANO_TINY */
filestruct
*
previous
=
indented_line
?
indented_line
:
openfile
->
current
;
filestruct
*
newnode
=
make_new_node
(
previous
);
newnode
->
data
=
charalloc
(
strlen
(
openfile
->
current
->
data
+
newnode
->
data
=
charalloc
(
strlen
(
openfile
->
current
->
data
+
openfile
->
current_x
)
+
extra
+
1
);
openfile
->
current_x
)
+
extra
+
1
);
strcpy
(
&
newnode
->
data
[
extra
],
openfile
->
current
->
data
+
strcpy
(
&
newnode
->
data
[
extra
],
openfile
->
current
->
data
+
...
@@ -916,12 +934,12 @@ void do_enter(void)
...
@@ -916,12 +934,12 @@ void do_enter(void)
#endif
#endif
/* Insert the newly created line after the current one and renumber. */
/* Insert the newly created line after the current one and renumber. */
splice_node
(
openfile
->
current
,
newnode
);
splice_node
(
previous
,
newnode
);
renumber
(
newnode
);
renumber
(
newnode
);
/* Put the cursor on the new line, after any automatic whitespace. */
/* Put the cursor on the new line, after any automatic whitespace. */
openfile
->
current
=
newnode
;
openfile
->
current
=
indented_line
?
indented_line
:
newnode
;
openfile
->
current_x
=
extra
;
openfile
->
current_x
=
indented_line
?
extra
+
tab_char_length
()
:
extra
;
openfile
->
placewewant
=
xplustabs
();
openfile
->
placewewant
=
xplustabs
();
openfile
->
totsize
++
;
openfile
->
totsize
++
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help