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
ea478799
Commit
ea478799
authored
7 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: don't construct the positions-history filename time and again
parent
bfc53f30
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/history.c
+14
-24
src/history.c
with
14 additions
and
24 deletions
+14
-24
src/history.c
View file @
ea478799
...
...
@@ -42,6 +42,8 @@ static bool history_changed = FALSE;
/* Whether any of the history lists has changed. */
static
struct
stat
stat_of_positions_file
;
/* The last-obtained stat information of the positions file. */
static
char
*
poshistname
=
NULL
;
/* The name of the positions-history file. */
/* Initialize the lists of historical search and replace strings
* and the list of historical executed commands. */
...
...
@@ -287,6 +289,9 @@ bool have_statedir(void)
return
FALSE
;
}
if
(
ISSET
(
POS_HISTORY
))
poshistname
=
concatenate
(
statedir
,
POSITION_HISTORY
);
return
TRUE
;
}
...
...
@@ -388,26 +393,16 @@ void save_history(void)
free
(
histname
);
}
/* Update the modification time of the position history file. */
void
update_posfile_timestamp
(
void
)
{
char
*
poshist
=
concatenate
(
statedir
,
POSITION_HISTORY
);
stat
(
poshist
,
&
stat_of_positions_file
);
free
(
poshist
);
}
/* Load the recorded cursor positions for files that were edited. */
void
load_poshistory
(
void
)
{
char
*
poshist
=
concatenate
(
statedir
,
POSITION_HISTORY
);
FILE
*
hisfile
=
fopen
(
poshist
,
"rb"
);
FILE
*
hisfile
=
fopen
(
poshistname
,
"rb"
);
if
(
hisfile
==
NULL
)
{
if
(
errno
!=
ENOENT
)
{
/* When reading failed, don't save history when we quit. */
UNSET
(
POS_HISTORY
);
history_error
(
N_
(
"Error reading %s: %s"
),
poshist
,
strerror
(
errno
));
history_error
(
N_
(
"Error reading %s: %s"
),
poshist
name
,
strerror
(
errno
));
}
}
else
{
char
*
line
=
NULL
,
*
lineptr
,
*
xptr
;
...
...
@@ -460,23 +455,21 @@ void load_poshistory(void)
fclose
(
hisfile
);
free
(
line
);
update_posfile_timestamp
(
);
stat
(
poshistname
,
&
stat_of_positions_file
);
}
free
(
poshist
);
}
/* Save the recorded cursor positions for files that were edited. */
void
save_poshistory
(
void
)
{
char
*
poshist
=
concatenate
(
statedir
,
POSITION_HISTORY
);
poshiststruct
*
posptr
;
FILE
*
hisfile
=
fopen
(
poshist
,
"wb"
);
FILE
*
hisfile
=
fopen
(
poshist
name
,
"wb"
);
if
(
hisfile
==
NULL
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
,
strerror
(
errno
));
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
name
,
strerror
(
errno
));
else
{
/* Don't allow others to read or write the history file. */
chmod
(
poshist
,
S_IRUSR
|
S_IWUSR
);
chmod
(
poshist
name
,
S_IRUSR
|
S_IWUSR
);
for
(
posptr
=
position_history
;
posptr
!=
NULL
;
posptr
=
posptr
->
next
)
{
char
*
path_and_place
;
...
...
@@ -496,24 +489,21 @@ void save_poshistory(void)
if
(
fwrite
(
path_and_place
,
sizeof
(
char
),
length
,
hisfile
)
<
length
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
,
strerror
(
errno
));
poshist
name
,
strerror
(
errno
));
free
(
path_and_place
);
}
fclose
(
hisfile
);
update_posfile_timestamp
(
);
stat
(
poshistname
,
&
stat_of_positions_file
);
}
free
(
poshist
);
}
/* Reload the position history file if it has been modified since last load. */
void
reload_positions_if_needed
(
void
)
{
char
*
poshist
=
concatenate
(
statedir
,
POSITION_HISTORY
);
struct
stat
newstat
;
stat
(
poshist
,
&
newstat
);
free
(
poshist
);
stat
(
poshistname
,
&
newstat
);
if
(
newstat
.
st_mtime
!=
stat_of_positions_file
.
st_mtime
)
{
poshiststruct
*
ptr
,
*
nextone
;
...
...
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