+% Variation Selector
+\def\ltj@lst@ProcessVS#1{%
+ \lst@whitespacefalse
+ \if@ltj@lst@vsraw
+ \lst@Append#1\advance\lst@length\m@ne
+ \else
+ \lst@TrackNewLines\lst@OutputLostSpace \lst@PrintToken
+ \setbox\@tempboxa\hbox to 2\lst@width{\hss
+ \expandafter\expandafter\expandafter\ltj@lst@vscmd
+ \expandafter{\the\numexpr`#1-"FDFF\relax}%"
+ \hss}%
+ \lst@CalcLostSpaceAndOutput\lst@whitespacefalse
+ \fi
+}
+
+
+% 半角カナ,異体字セレクタはアクティブ化
+\def\ltj@@listing@jpsetN#1#2#3{% for (not large) range
+ \@tempcnta=\numexpr#1-1\relax\@tempcntb=\numexpr 1+#2\relax
+ \loop \global\advance\@tempcnta\@ne\ifnum\@tempcnta<\@tempcntb\relax
+ \ltj@@listing@jpsetN@{\@tempcnta}{#3}\repeat
+}
+
+\def\ltj@@listing@jpsetN@#1#2{{%
+ \@tempcnta=#1 \lccode`\~=\@tempcnta \lccode`\/=\@tempcnta
+ \lowercase{\gdef\@temp{\gdef~{#2/}}}}%
+ \@temptokena\expandafter\expandafter\expandafter\expandafter%
+ \expandafter\expandafter\expandafter{\expandafter\expandafter%
+ \expandafter\the\expandafter\@temptokena\@temp}%
+}
+\@temptokena{}
+\ltj@@listing@jpsetN{65377}{65439}{\ltj@lst@ProcessJALetterHalf}
+\ltj@@listing@jpsetN{65024}{65039}{\ltj@lst@ProcessVS}
+\ltj@@listing@jpsetN{917760}{917999}{\ltj@lst@ProcessIVS}
+\xdef\ltj@@listing@jpcmd{\the\@temptokena}\@temptokena{}
+
+% catcode 対策
+\newluatexcatcodetable\CatcodeTableLTJlistings
+\setluatexcatcodetable\CatcodeTableLTJlistings{%
+ \luatexcatcodetable\CatcodeTableLaTeXAtLetter
+ \catcode"FFFFF=13%"
+ \SetCatcodeRange{"FF61}{"FF9F}{13}% 半角カナ
+ \SetCatcodeRange{"E0100}{"E01EF}{13}% 漢字用異体字セレクタ
+ \SetCatcodeRange{"FE00}{"FE0F}{13}% Variation Selector
+}
+
+% We redefine \lst@BeginDropInput, since now we have
+% two additional `process macros'.
+\def\lst@BeginDropInput#1{%
+ \lst@EnterMode{#1}%
+ {\lst@modetrue
+ \let\lst@OutputBox\@gobble
+ \let\lst@ifdropinput\iftrue
+ \let\lst@ProcessLetter\@gobble
+ \let\lst@ProcessDigit\@gobble
+ \let\lst@ProcessOther\@gobble
+ \let\lst@ProcessSpace\@empty
+ \let\lst@ProcessTabulator\@empty
+ \let\lst@ProcessFormFeed\@empty
+ \let\ltj@lst@ProcessJALetter\@gobble % added
+ \let\ltj@lst@ProcessJALetterHalf\@gobble % added
+}}
+
+
+% hook!
+\lst@AddToHook{Init}{%
+ \luatexcatcodetable\CatcodeTableLTJlistings\ltj@@listing@jpcmd
+ \lccode`\~="FFFFF\lowercase{\def~{\ltj@lst@ProcessJALetter}}%"
+ \directlua{luatexbase.add_to_callback('process_input_buffer',
+ function(buf)
+ local ret = ''
+ for i = 1, utf.len(buf) do
+ local c = utf.sub(buf, i, i)
+ local cu = utf.byte(c)
+ if cu > 0x80 and tex.getcatcode(cu) \string~= 13 then
+ ret = ret .. utf.char(1048575) % U+FFFFF
+ end
+ ret = ret .. c
+ end
+ return ret
+ end, 'ltj.listings_unicode', 1)}%
+ \if@ltj@lst@vsraw
+ \let\ltj@lst@hss=\ltj@lst@hss@ivs
+ \else
+ \let\ltj@lst@hss=\lst@hss
+ \fi
+}
+\lst@AddToHook{ExitVars}{%
+ \directlua{luatexbase.remove_from_callback('process_input_buffer',
+ 'ltj.listings_unicode')}%
+}
+
+
+% 白線対策
+\def\lst@OutputToken{%
+ \lst@TrackNewLines \lst@OutputLostSpace
+ \lst@ifgobbledws
+ \lst@gobbledwhitespacefalse
+ \lst@@discretionary
+ \fi
+ \lst@CheckMerge
+ {\lst@thestyle{\lst@FontAdjust
+ \setbox\@tempboxa\lst@hbox
+ {\lsthk@OutputBox
+ \lst@lefthss
+ \expandafter\lst@FillOutputBox\the\lst@token\@empty
+ \lst@righthss}%
+ \ht\@tempboxa=0pt\dp\@tempboxa=0pt
+ \lst@CalcLostSpaceAndOutput}}%
+ \lst@ResetToken}
+
+%%%%%%%%%%%%%%%% escape to \LaTeX
+\lstloadaspects{escape}
+\gdef\lst@Escape#1#2#3#4{%
+ \lst@CArgX #1\relax\lst@CDefX
+ {}%
+ {\lst@ifdropinput\else
+ \lst@TrackNewLines\lst@OutputLostSpace \lst@XPrintToken
+ \lst@InterruptModes
+ \lst@EnterMode{\lst@TeXmode}{\lst@modetrue}%
+ \ifx\^^M#2%
+ \lst@CArg #2\relax\lst@ActiveCDefX
+ {}%
+ {\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes}%
+ {\lst@MProcessListing}%
+ \else
+ \lst@CArg #2\relax\lst@ActiveCDefX
+ {}%
+ {\lst@escapeend #4\lst@LeaveAllModes\lst@ReenterModes
+ \lst@newlines\z@ \lst@whitespacefalse}%
+ {}%
+ \fi
+ #3\catcode"FFFFF=9\lst@escapebegin%"
+ \fi}%
+ {}}
+
+%%%%%%%%%%%%%%%%
+\lstloadaspects{writefile}
+\begingroup \catcode`\^^I=11
+\gdef\lst@WFBegin#1#2{%
+ \begingroup
+ \let\lst@OutputBox#1%
+ \def\lst@Append##1{%
+ \advance\lst@length\@ne
+ \expandafter\lst@token\expandafter{\the\lst@token##1}%
+ \ifx ##1\lst@outputspace \else
+ \lst@WFAppend##1%
+ \fi}%
+ \lst@lAddTo\lst@PreGotoTabStop{\lst@WFAppend{^^I}}%
+ \lst@lAddTo\lst@ProcessSpace{\lst@WFAppend{ }}%
+ \def\ltj@lst@ProcessIVS##1{\lst@whitespacefalse\lst@Append##1}%
+ \def\ltj@lst@ProcessVS##1{\lst@whitespacefalse\lst@Append##1}%
+ \let\lst@DeInit\lst@WFDeInit
+ \let\lst@MProcessListing\lst@WFMProcessListing
+ \lst@WFifopen\else
+ \immediate\openout\lst@WF=#2\relax
+ \global\let\lst@WFifopen\iftrue
+ \@gobbletwo\fi\fi
+ \fi}
+\endgroup
+
+
+% \begin{修正事項}{1.3} from jlisting.sty