1
0
mirror of https://github.com/amix/vimrc synced 2025-07-10 03:25:00 +08:00

Add markdown preview, update rust.vim

This commit is contained in:
Kurtis Moxley
2022-05-19 20:12:11 +08:00
parent d26bc75459
commit d6ef288a88
156 changed files with 29900 additions and 0 deletions

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const load_1 = tslib_1.__importDefault(require("./load"));
const PATH = '--path';
const VERSION = '--version';
const { argv = [] } = process;
const param = argv[2];
if (param === PATH) {
(0, load_1.default)(argv[3]).run();
}
else if (param === VERSION) {
// tslint:disable-next-line
console.log('0.0.10');
}

View File

@ -0,0 +1 @@
export default function load(scriptPath: any): any;

View File

@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fs_1 = tslib_1.__importDefault(require("fs"));
const module_1 = tslib_1.__importDefault(require("module"));
const path_1 = tslib_1.__importDefault(require("path"));
const vm_1 = tslib_1.__importDefault(require("vm"));
const preloadmodules_1 = tslib_1.__importDefault(require("./preloadmodules"));
function load(scriptPath) {
const userModule = new module_1.default(scriptPath);
userModule.filename = scriptPath;
userModule.paths = module_1.default._nodeModulePaths(path_1.default.dirname(scriptPath));
const moduleCode = fs_1.default.readFileSync(userModule.filename, 'utf-8');
userModule.require = userModule.require.bind(userModule);
const sanbox = vm_1.default.createContext(Object.assign(Object.assign({}, global), { exports: userModule.exports, module: userModule, require: name => {
if (preloadmodules_1.default[name]) {
return preloadmodules_1.default[name];
}
try {
return userModule.require(name);
}
catch (e) {
let loadScript = path_1.default.join(path_1.default.dirname(scriptPath), name);
if (fs_1.default.existsSync(loadScript) && fs_1.default.statSync(loadScript).isDirectory()) {
loadScript = path_1.default.join(loadScript, 'index.js');
}
else if (!fs_1.default.existsSync(loadScript)) {
loadScript = `${loadScript}.js`;
}
return load(loadScript);
}
}, __filename: userModule.filename, __dirname: path_1.default.dirname(scriptPath), process }));
vm_1.default.runInContext(moduleCode, sanbox, { filename: userModule.filename });
return userModule.exports;
}
exports.default = load;

View File

@ -0,0 +1,8 @@
declare const _default: {
'@chemzqm/neovim': any;
log4js: any;
tslib: any;
'socket.io': any;
'msgpack-lite': any;
};
export default _default;

View File

@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const neovim = require('@chemzqm/neovim');
const log4js = require('log4js');
const tslib = require('tslib');
const socketIO = require('socket.io');
const msgpackLite = require('msgpack-lite');
exports.default = {
'@chemzqm/neovim': neovim,
log4js,
tslib,
'socket.io': socketIO,
'msgpack-lite': msgpackLite
};

View File

@ -0,0 +1,20 @@
import { Attach, NeovimClient } from '@chemzqm/neovim';
interface IApp {
refreshPage: ((param: {
bufnr: number | string;
data: any;
}) => void);
closePage: ((params: {
bufnr: number | string;
}) => void);
closeAllPages: (() => void);
openBrowser: ((params: {
bufnr: number | string;
}) => void);
}
interface IPlugin {
init: ((app: IApp) => void);
nvim: NeovimClient;
}
export default function (options: Attach): IPlugin;
export {};

View File

@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const neovim_1 = require("@chemzqm/neovim");
const logger = require('../util/logger')('attach'); // tslint:disable-line
let app;
function default_1(options) {
const nvim = (0, neovim_1.attach)(options);
nvim.on('notification', (method, args) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const opts = args[0] || args;
const bufnr = opts.bufnr;
const buffers = yield nvim.buffers;
const buffer = buffers.find(b => b.id === bufnr);
if (method === 'refresh_content') {
const winline = yield nvim.call('winline');
const currentWindow = yield nvim.window;
const winheight = yield nvim.call('winheight', currentWindow.id);
const cursor = yield nvim.call('getpos', '.');
const renderOpts = yield nvim.getVar('mkdp_preview_options');
const pageTitle = yield nvim.getVar('mkdp_page_title');
const theme = yield nvim.getVar('mkdp_theme');
const name = yield buffer.name;
const content = yield buffer.getLines();
const currentBuffer = yield nvim.buffer;
app.refreshPage({
bufnr,
data: {
options: renderOpts,
isActive: currentBuffer.id === buffer.id,
winline,
winheight,
cursor,
pageTitle,
theme,
name,
content
}
});
}
else if (method === 'close_page') {
app.closePage({
bufnr
});
}
else if (method === 'open_browser') {
app.openBrowser({
bufnr
});
}
}));
nvim.on('request', (method, args, resp) => {
if (method === 'close_all_pages') {
app.closeAllPages();
}
resp.send();
});
nvim.channelId
.then((channelId) => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield nvim.setVar('mkdp_node_channel_id', channelId);
}))
.catch(e => {
logger.error('channelId: ', e);
});
return {
nvim,
init: (param) => {
app = param;
}
};
}
exports.default = default_1;

View File

@ -0,0 +1 @@
export declare function getIP(): string;

View File

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIP = void 0;
function getIP() {
const interfaces = require('os').networkInterfaces();
let IP = '';
Object.keys(interfaces).some(devName => {
const iface = interfaces[devName];
for (const alias of iface) {
if (alias.family === 'IPv4' &&
alias.address !== '127.0.0.1' &&
!alias.internal) {
IP = alias.address;
return true;
}
}
return false;
});
return IP;
}
exports.getIP = getIP;

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fs_1 = tslib_1.__importDefault(require("fs"));
const log4js_1 = tslib_1.__importDefault(require("log4js"));
const os_1 = tslib_1.__importDefault(require("os"));
const path_1 = tslib_1.__importDefault(require("path"));
const MAX_LOG_SIZE = 1024 * 1024;
const MAX_LOG_BACKUPS = 10;
const LOG_FILE_PATH = process.env.NVIM_MKDP_LOG_FILE || path_1.default.join(os_1.default.tmpdir(), 'mkdp-nvim.log');
const level = process.env.NVIM_MKDP_LOG_LEVEL || 'info';
if (level === 'debug') {
fs_1.default.writeFileSync(LOG_FILE_PATH, '', 'utf8');
}
const isRoot = process.getuid && process.getuid() === 0;
if (!isRoot) {
log4js_1.default.configure({
appenders: {
out: {
type: 'file',
filename: LOG_FILE_PATH,
maxLogSize: MAX_LOG_SIZE,
backups: MAX_LOG_BACKUPS,
layout: {
type: 'pattern',
// Format log in following pattern:
// yyyy-MM-dd HH:mm:ss.mil $Level (pid:$pid) $categroy - $message.
pattern: `%d{yyyy-MM-dd hh:mm:ss} %p (pid:${process.pid}) [%c] - %m`
}
}
},
categories: {
default: { appenders: ['out'], level }
}
});
}
module.exports = (name = 'mkdp') => {
return log4js_1.default.getLogger(name);
};

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/*
* fork from https://github.com/domenic/opener
*/
const child_process_1 = tslib_1.__importDefault(require("child_process"));
const os_1 = tslib_1.__importDefault(require("os"));
module.exports = function opener(args, tool) {
let platform = process.platform;
args = [].concat(args);
// Attempt to detect Windows Subystem for Linux (WSL).
// WSL itself as Linux (which works in most cases), but in
// this specific case we need to treat it as actually being Windows.
// The "Windows-way" of opening things through cmd.exe works just fine here,
// whereas using xdg-open does not, since there is no X Windows in WSL.
if (platform === 'linux' && os_1.default.release().toLowerCase().indexOf('microsoft') !== -1) {
platform = 'win32';
}
// http://stackoverflow.com/q/1480971/3191, but see below for Windows.
let command;
switch (platform) {
case 'win32': {
command = 'cmd.exe';
if (tool) {
args.unshift(tool);
}
break;
}
case 'darwin': {
command = 'open';
if (tool) {
args.unshift(tool);
args.unshift('-a');
}
break;
}
default: {
command = tool || 'xdg-open';
break;
}
}
if (platform === 'win32') {
// On Windows, we really want to use the "start" command.
// But, the rules regarding arguments with spaces, and escaping them with quotes,
// can get really arcane. So the easiest way to deal with this is to pass off the
// responsibility to "cmd /c", which has that logic built in.
//
// Furthermore, if "cmd /c" double-quoted the first parameter,
// then "start" will interpret it as a window title,
// so we need to add a dummy empty-string window title: http://stackoverflow.com/a/154090/3191
//
// Additionally, on Windows ampersand needs to be escaped when passed to "start"
args = args.map(value => {
return value.replace(/&/g, '^&');
});
args = ['/c', 'start', '""'].concat(args);
}
return child_process_1.default.spawn(command, args, {
shell: false,
detached: true
});
};