Read/write command history from/to a file. More...
#include "config.h"#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include "mutt/lib.h"#include "config/lib.h"#include "core/lib.h"#include "lib.h"
Include dependency graph for history.c:Go to the source code of this file.
Data Structures | |
| struct | History |
| Saved list of user-entered commands/searches. More... | |
Macros | |
| #define | HC_FIRST HC_EXT_COMMAND |
Functions | |
| static struct History * | get_history (enum HistoryClass hclass) |
| Get a particular history. | |
| static void | init_history (struct History *h) |
| Set up a new History ring buffer. | |
| static int | dup_hash_dec (struct HashTable *dup_hash, char *str) |
| Decrease the refcount of a history string. | |
| static int | dup_hash_inc (struct HashTable *dup_hash, char *str) |
| Increase the refcount of a history string. | |
| static void | shrink_histfile (void) |
| Read, de-dupe and write the history file. | |
| static void | save_history (enum HistoryClass hclass, const char *str) |
| Save one history string to a file. | |
| static void | remove_history_dups (enum HistoryClass hclass, const char *str) |
| De-dupe the history. | |
| int | mutt_hist_search (const char *find, enum HistoryClass hclass, struct StringArray *matches) |
| Find matches in a history list. | |
| void | mutt_hist_cleanup (void) |
| Free all the history lists. | |
| void | mutt_hist_init (void) |
| Create a set of empty History ring buffers. | |
| void | mutt_hist_add (enum HistoryClass hclass, const char *str, bool save) |
| Add a string to a history. | |
| char * | mutt_hist_next (enum HistoryClass hclass) |
| Get the next string in a History. | |
| char * | mutt_hist_prev (enum HistoryClass hclass) |
| Get the previous string in a History. | |
| void | mutt_hist_reset_state (enum HistoryClass hclass) |
| Move the 'current' position to the end of the History. | |
| void | mutt_hist_read_file (void) |
| Read the History from a file. | |
| bool | mutt_hist_at_scratch (enum HistoryClass hclass) |
| Is the current History position at the 'scratch' place? | |
| void | mutt_hist_save_scratch (enum HistoryClass hclass, const char *str) |
| Save a temporary string to the History. | |
| void | mutt_hist_complete (struct Buffer *buf, enum HistoryClass hclass) |
| Complete a string from a history list. | |
| int | main_hist_observer (struct NotifyCallback *nc) |
| Notification that a Config Variable has change - Implements observer_t -. | |
Variables | |
| static struct History | Histories [HC_MAX] |
| Command histories, one for each HistoryClass. | |
| static int | OldSize = 0 |
| The previous number of history entries to save. | |
Read/write command history from/to a file.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file history.c.
| #define HC_FIRST HC_EXT_COMMAND |
|
static |
Get a particular history.
| hclass | Type of history to find |
| ptr | History ring buffer |
Definition at line 110 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Set up a new History ring buffer.
| h | History to populate |
If the History already has entries, they will be freed.
Definition at line 126 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Decrease the refcount of a history string.
| dup_hash | Hash Table containing unique history strings |
| str | String to find |
| 0 | String was deleted from the Hash Table |
| >0 | Refcount of string |
| -1 | Error, string not found |
If the string's refcount is 1, then the string will be deleted.
Definition at line 156 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Increase the refcount of a history string.
| dup_hash | Hash Table containing unique history strings |
| str | String to find |
| num | Refcount of string |
If the string isn't found it will be added to the Hash Table.
Definition at line 182 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Read, de-dupe and write the history file.
Definition at line 203 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Save one history string to a file.
| hclass | History type |
| str | String to save |
Definition at line 317 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
De-dupe the history.
| hclass | History to de-dupe |
| str | String to find |
If the string is found, it is removed from the history.
When removing dups, we want the created "blanks" to be right below the resulting h->last position. See the comment section above 'struct History'.
Definition at line 355 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int mutt_hist_search | ( | const char * | find, |
| enum HistoryClass | hclass, | ||
| struct StringArray * | matches ) |
Find matches in a history list.
| [in] | find | String to find |
| [in] | hclass | History list |
| [out] | matches | All the matching lines |
| num | Matches found |
Definition at line 405 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_cleanup | ( | void | ) |
Free all the history lists.
Definition at line 437 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_init | ( | void | ) |
Create a set of empty History ring buffers.
This just creates empty histories. To fill them, call mutt_hist_read_file().
Definition at line 464 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_add | ( | enum HistoryClass | hclass, |
| const char * | str, | ||
| bool | save ) |
Add a string to a history.
| hclass | History to add to |
| str | String to add |
| save | Should the changes be saved to file immediately? |
Definition at line 482 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| char * mutt_hist_next | ( | enum HistoryClass | hclass | ) |
Get the next string in a History.
| hclass | History to choose |
| ptr | Next string |
If there is no next string, and empty string will be returned.
Definition at line 522 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| char * mutt_hist_prev | ( | enum HistoryClass | hclass | ) |
Get the previous string in a History.
| hclass | History to choose |
| ptr | Previous string |
If there is no previous string, and empty string will be returned.
Definition at line 550 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_reset_state | ( | enum HistoryClass | hclass | ) |
Move the 'current' position to the end of the History.
| hclass | History to reset |
After calling mutt_hist_next() and mutt_hist_prev(), this function resets the current position ('cur' pointer).
Definition at line 578 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_read_file | ( | void | ) |
Read the History from a file.
The file $history_file is read and parsed into separate History ring buffers.
Definition at line 592 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| bool mutt_hist_at_scratch | ( | enum HistoryClass | hclass | ) |
Is the current History position at the 'scratch' place?
| hclass | History to use |
| true | History is at 'scratch' place |
The last entry in the history is used as a 'scratch' area. It can be overwritten as the user types and edits.
To get (back) to the scratch area, call mutt_hist_next(), mutt_hist_prev() or mutt_hist_reset_state().
Definition at line 644 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_save_scratch | ( | enum HistoryClass | hclass, |
| const char * | str ) |
Save a temporary string to the History.
| hclass | History to alter |
| str | String to set |
Write a 'scratch' string into the History's current position. This is useful to preserver a user's edits.
Definition at line 661 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void mutt_hist_complete | ( | struct Buffer * | buf, |
| enum HistoryClass | hclass ) |
Complete a string from a history list.
Definition at line 677 of file history.c.
Here is the call graph for this function:
Here is the caller graph for this function:Command histories, one for each HistoryClass.