Created
January 22, 2011 08:27
-
-
Save nissuk/790982 to your computer and use it in GitHub Desktop.
Notepad++にUnicodeエスケープ/アンエスケープをするメニュー(「my」)を追加する(NppScripting\includesに配置して下さい)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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