mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
shada: Add support for merging everything like described in the doc
This commit is contained in:
parent
4bc053facd
commit
43fe98c9fb
@ -196,6 +196,7 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
|
|
||||||
#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
|
#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
|
||||||
extern kh_##name##_t *kh_init_##name(void); \
|
extern kh_##name##_t *kh_init_##name(void); \
|
||||||
|
extern void kh_dealloc_##name(kh_##name##_t *h); \
|
||||||
extern void kh_destroy_##name(kh_##name##_t *h); \
|
extern void kh_destroy_##name(kh_##name##_t *h); \
|
||||||
extern void kh_clear_##name(kh_##name##_t *h); \
|
extern void kh_clear_##name(kh_##name##_t *h); \
|
||||||
extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
|
extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
|
||||||
@ -204,16 +205,24 @@ static const double __ac_HASH_UPPER = 0.77;
|
|||||||
extern void kh_del_##name(kh_##name##_t *h, khint_t x);
|
extern void kh_del_##name(kh_##name##_t *h, khint_t x);
|
||||||
|
|
||||||
#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||||
|
SCOPE kh_##name##_t *kh_init_##name(void) \
|
||||||
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE kh_##name##_t *kh_init_##name(void) { \
|
SCOPE kh_##name##_t *kh_init_##name(void) { \
|
||||||
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
|
return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
|
||||||
} \
|
} \
|
||||||
|
SCOPE void kh_dealloc_##name(kh_##name##_t *h) \
|
||||||
|
REAL_FATTR_UNUSED; \
|
||||||
|
SCOPE void kh_dealloc_##name(kh_##name##_t *h) \
|
||||||
|
{ \
|
||||||
|
kfree((void *)h->keys); kfree(h->flags); \
|
||||||
|
kfree((void *)h->vals); \
|
||||||
|
} \
|
||||||
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
||||||
REAL_FATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
||||||
{ \
|
{ \
|
||||||
if (h) { \
|
if (h) { \
|
||||||
kfree((void *)h->keys); kfree(h->flags); \
|
kh_dealloc_##name(h); \
|
||||||
kfree((void *)h->vals); \
|
|
||||||
kfree(h); \
|
kfree(h); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@ -446,6 +455,13 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
|
|||||||
*/
|
*/
|
||||||
#define kh_destroy(name, h) kh_destroy_##name(h)
|
#define kh_destroy(name, h) kh_destroy_##name(h)
|
||||||
|
|
||||||
|
/*! @function
|
||||||
|
@abstract Free memory referenced directly inside a hash table.
|
||||||
|
@param name Name of the hash table [symbol]
|
||||||
|
@param h Pointer to the hash table [khash_t(name)*]
|
||||||
|
*/
|
||||||
|
#define kh_dealloc(name, h) kh_dealloc_##name(h)
|
||||||
|
|
||||||
/*! @function
|
/*! @function
|
||||||
@abstract Reset a hash table without deallocating memory.
|
@abstract Reset a hash table without deallocating memory.
|
||||||
@param name Name of the hash table [symbol]
|
@param name Name of the hash table [symbol]
|
||||||
|
@ -1350,12 +1350,8 @@ size_t mark_buffer_amount(const buf_T *const buf)
|
|||||||
/// later then existing one.
|
/// later then existing one.
|
||||||
void mark_set_global(const char name, const xfmark_T fm, const bool update)
|
void mark_set_global(const char name, const xfmark_T fm, const bool update)
|
||||||
{
|
{
|
||||||
xfmark_T *fm_tgt = NULL;
|
xfmark_T *fm_tgt = &(namedfm[mark_global_index(name)]);
|
||||||
if (ASCII_ISUPPER(name)) {
|
if (fm_tgt == &namedfm[-1]) {
|
||||||
fm_tgt = &(namedfm[name - 'A']);
|
|
||||||
} else if (ascii_isdigit(name)) {
|
|
||||||
fm_tgt = &(namedfm[NMARKS + (name - '0')]);
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (update && fm.fmark.timestamp < fm_tgt->fmark.timestamp) {
|
if (update && fm.fmark.timestamp < fm_tgt->fmark.timestamp) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef NVIM_MARK_H
|
#ifndef NVIM_MARK_H
|
||||||
#define NVIM_MARK_H
|
#define NVIM_MARK_H
|
||||||
|
|
||||||
|
#include "nvim/macros.h"
|
||||||
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/buffer_defs.h"
|
#include "nvim/buffer_defs.h"
|
||||||
#include "nvim/mark_defs.h"
|
#include "nvim/mark_defs.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
@ -46,6 +48,32 @@
|
|||||||
SET_FMARK(&(xfmarkp__->fmark), mark_, fnum_); \
|
SET_FMARK(&(xfmarkp__->fmark), mark_, fnum_); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
/// Convert mark name to the offset
|
||||||
|
static inline int mark_global_index(const char name)
|
||||||
|
FUNC_ATTR_CONST
|
||||||
|
{
|
||||||
|
return (ASCII_ISUPPER(name)
|
||||||
|
? (name - 'A')
|
||||||
|
: (ascii_isdigit(name)
|
||||||
|
? (NMARKS + (name - '0'))
|
||||||
|
: -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert local mark name to the offset
|
||||||
|
static inline int mark_local_index(const char name)
|
||||||
|
FUNC_ATTR_CONST
|
||||||
|
{
|
||||||
|
return (ASCII_ISLOWER(name)
|
||||||
|
? (name - 'a')
|
||||||
|
: (name == '"'
|
||||||
|
? NMARKS
|
||||||
|
: (name == '^'
|
||||||
|
? NMARKS + 1
|
||||||
|
: (name == '.'
|
||||||
|
? NMARKS + 2
|
||||||
|
: -1))));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "mark.h.generated.h"
|
# include "mark.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,6 +19,12 @@
|
|||||||
/// Total possible number of global marks
|
/// Total possible number of global marks
|
||||||
#define NGLOBALMARKS (NMARKS + EXTRA_MARKS)
|
#define NGLOBALMARKS (NMARKS + EXTRA_MARKS)
|
||||||
|
|
||||||
|
/// Total possible number of local marks
|
||||||
|
///
|
||||||
|
/// That are uppercase marks plus '"', '^' and '.'. There are other local marks,
|
||||||
|
/// but they are not saved in ShaDa files.
|
||||||
|
#define NLOCALMARKS (NMARKS + 3)
|
||||||
|
|
||||||
/// Maximum number of marks in jump list
|
/// Maximum number of marks in jump list
|
||||||
#define JUMPLISTSIZE 100
|
#define JUMPLISTSIZE 100
|
||||||
|
|
||||||
|
@ -54,22 +54,6 @@
|
|||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* Registers:
|
|
||||||
* 0 = register for latest (unnamed) yank
|
|
||||||
* 1..9 = registers '1' to '9', for deletes
|
|
||||||
* 10..35 = registers 'a' to 'z'
|
|
||||||
* 36 = delete register '-'
|
|
||||||
* 37 = selection register '*'
|
|
||||||
* 38 = clipboard register '+'
|
|
||||||
*/
|
|
||||||
#define DELETION_REGISTER 36
|
|
||||||
#define NUM_SAVED_REGISTERS 37
|
|
||||||
// The following registers should not be saved in ShaDa file:
|
|
||||||
#define STAR_REGISTER 37
|
|
||||||
#define PLUS_REGISTER 38
|
|
||||||
#define NUM_REGISTERS 39
|
|
||||||
|
|
||||||
static yankreg_T y_regs[NUM_REGISTERS];
|
static yankreg_T y_regs[NUM_REGISTERS];
|
||||||
|
|
||||||
static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */
|
static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */
|
||||||
@ -749,31 +733,6 @@ typedef enum {
|
|||||||
YREG_PUT,
|
YREG_PUT,
|
||||||
} yreg_mode_t;
|
} yreg_mode_t;
|
||||||
|
|
||||||
/// Convert register name into register index
|
|
||||||
///
|
|
||||||
/// @param[in] regname Register name.
|
|
||||||
///
|
|
||||||
/// @return Index in y_regs array or -1 if register name was not recognized.
|
|
||||||
static inline int reg_index(const int regname)
|
|
||||||
FUNC_ATTR_CONST
|
|
||||||
{
|
|
||||||
if (ascii_isdigit(regname)) {
|
|
||||||
return regname - '0';
|
|
||||||
} else if (ASCII_ISLOWER(regname)) {
|
|
||||||
return CharOrdLow(regname) + 10;
|
|
||||||
} else if (ASCII_ISUPPER(regname)) {
|
|
||||||
return CharOrdUp(regname) + 10;
|
|
||||||
} else if (regname == '-') {
|
|
||||||
return DELETION_REGISTER;
|
|
||||||
} else if (regname == '*') {
|
|
||||||
return STAR_REGISTER;
|
|
||||||
} else if (regname == '+') {
|
|
||||||
return PLUS_REGISTER;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return yankreg_T to use, according to the value of `regname`.
|
/// Return yankreg_T to use, according to the value of `regname`.
|
||||||
/// Cannot handle the '_' (black hole) register.
|
/// Cannot handle the '_' (black hole) register.
|
||||||
/// Must only be called with a valid register name!
|
/// Must only be called with a valid register name!
|
||||||
@ -806,7 +765,7 @@ yankreg_T *get_yank_register(int regname, int mode)
|
|||||||
return y_previous;
|
return y_previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = reg_index(regname);
|
int i = op_reg_index(regname);
|
||||||
// when not 0-9, a-z, A-Z or '-'/'+'/'*': use register 0
|
// when not 0-9, a-z, A-Z or '-'/'+'/'*': use register 0
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -5417,7 +5376,7 @@ size_t op_register_amount(void)
|
|||||||
/// Set register to a given value
|
/// Set register to a given value
|
||||||
void register_set(const char name, const yankreg_T reg)
|
void register_set(const char name, const yankreg_T reg)
|
||||||
{
|
{
|
||||||
int i = reg_index(name);
|
int i = op_reg_index(name);
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "nvim/macros.h"
|
||||||
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/types.h"
|
#include "nvim/types.h"
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
@ -17,6 +19,22 @@ typedef int (*Indenter)(void);
|
|||||||
#define PUT_LINE_SPLIT 16 /* split line for linewise register */
|
#define PUT_LINE_SPLIT 16 /* split line for linewise register */
|
||||||
#define PUT_LINE_FORWARD 32 /* put linewise register below Visual sel. */
|
#define PUT_LINE_FORWARD 32 /* put linewise register below Visual sel. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Registers:
|
||||||
|
* 0 = register for latest (unnamed) yank
|
||||||
|
* 1..9 = registers '1' to '9', for deletes
|
||||||
|
* 10..35 = registers 'a' to 'z'
|
||||||
|
* 36 = delete register '-'
|
||||||
|
* 37 = selection register '*'
|
||||||
|
* 38 = clipboard register '+'
|
||||||
|
*/
|
||||||
|
#define DELETION_REGISTER 36
|
||||||
|
#define NUM_SAVED_REGISTERS 37
|
||||||
|
// The following registers should not be saved in ShaDa file:
|
||||||
|
#define STAR_REGISTER 37
|
||||||
|
#define PLUS_REGISTER 38
|
||||||
|
#define NUM_REGISTERS 39
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Operator IDs; The order must correspond to opchars[] in ops.c!
|
* Operator IDs; The order must correspond to opchars[] in ops.c!
|
||||||
*/
|
*/
|
||||||
@ -66,6 +84,31 @@ typedef struct yankreg {
|
|||||||
Dictionary *additional_data; ///< Additional data from ShaDa file.
|
Dictionary *additional_data; ///< Additional data from ShaDa file.
|
||||||
} yankreg_T;
|
} yankreg_T;
|
||||||
|
|
||||||
|
/// Convert register name into register index
|
||||||
|
///
|
||||||
|
/// @param[in] regname Register name.
|
||||||
|
///
|
||||||
|
/// @return Index in y_regs array or -1 if register name was not recognized.
|
||||||
|
static inline int op_reg_index(const int regname)
|
||||||
|
FUNC_ATTR_CONST
|
||||||
|
{
|
||||||
|
if (ascii_isdigit(regname)) {
|
||||||
|
return regname - '0';
|
||||||
|
} else if (ASCII_ISLOWER(regname)) {
|
||||||
|
return CharOrdLow(regname) + 10;
|
||||||
|
} else if (ASCII_ISUPPER(regname)) {
|
||||||
|
return CharOrdUp(regname) + 10;
|
||||||
|
} else if (regname == '-') {
|
||||||
|
return DELETION_REGISTER;
|
||||||
|
} else if (regname == '*') {
|
||||||
|
return STAR_REGISTER;
|
||||||
|
} else if (regname == '+') {
|
||||||
|
return PLUS_REGISTER;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "ops.h.generated.h"
|
# include "ops.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
1209
src/nvim/shada.c
1209
src/nvim/shada.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user