Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created January 22, 2011 08:27
Show Gist options
  • Save nissuk/790982 to your computer and use it in GitHub Desktop.
Save nissuk/790982 to your computer and use it in GitHub Desktop.
Notepad++にUnicodeエスケープ/アンエスケープをするメニュー(「my」)を追加する(NppScripting\includesに配置して下さい)
(function(){
var menu = Editor.addMenu('my');
addMenuItem(menu, {
name: 'text to unicode escape',
key: 'Ctrl+U',
action: function(){ Editor.currentView.text = toUnicodeEscape(Editor.currentView.text) }
});
addMenuItem(menu, {
name: 'unicode escape to text',
key: 'Ctrl+Shift+U',
action: function(){ Editor.currentView.text = fromUnicodeEscape(Editor.currentView.text) }
});
function toUnicodeEscape(s) {
return s.replace(/[^\x00-\x7f]/g, function (c) {
return '\\u' + ('0000' + c.charCodeAt(0).toString(16).toUpperCase()).slice(-4);
});
}
function fromUnicodeEscape(s) {
return s.replace(/\\u[0-9A-Z]{4}/ig, function(escape) {
return String.fromCharCode(parseInt(escape.slice(2), 16));
});
}
// based on Zen Coding.js
function addMenuItem(menu, options) {
var item = {
text: options.name + (options.key ? '\t' + options.key : ''),
cmd: options.action,
ctrl: false,
alt: false,
shift: false
};
if (options.key) {
options.key.split('+').forEach(function(key){
key = key.toLowerCase();
switch (key) {
case 'shift':
case 'alt':
case 'ctrl':
item[key] = true;
break;
default:
item.key = key;
}
});
Editor.addSystemHotKey(item);
}
menu.addItem(item);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment