How to type Chinese or Japanese with TextMate?
Sometimes I have to write scripts, html pages, etc. with Chinese,
Japanese, Korean, etc. strings.
The problem is that within TextMate I cannot use e.g. Kotoeri (the
Japanese Input Editor) because I don't see what I'm typing. In order
to avoid to change to an other program I wrote a very easy code
snippet with CocoaDialog's textbox feature.
Here is one way to use my suggestion:
- open the Bundle Editor
- Show all
- go to the folder 'TextMate' (or whatever)
- add a new command 'inputCJK' (or whatever)
Command data
- Save: nothing
- Command(s):
# open CocoaDialog's textbox
res=$(CocoaDialog textbox \
--title "Input CJK" \
--informative-text "Write up here..." \
--selected \
--scroll-top top \
--editable \
--no-newline \
--button1 "Insert" \
--button2 "Cancel")
# If user canceled exit.
[[ $( (tail -r <<<"$res") | tail -n1) == "2" ]] && \
exit_discard
# delete first line
res=$(sed '1,1d' <<<"$res")
# print the content of the textbox
echo -n "$res"
Input: None
Output: Insert as Snippet
Activation: Key Equivalent shift+option+i (or whatever)
Scope: leave it empty
With the help of this script you are able to use Kotoeri or other IME
within TM indirectly.
I know that isn't the most elegant way but for writing small scripts
using some Japanese, Chinese strings is quite good.
Of course, TM has some problems to display Chinese characaters but, as
I mentioned before, for smaller things it is sufficient. ;)
Hopefully the very tiny script is useful for others as well. Feedback
is highly welcomed.
Many greetings,
Hans-Jörg Bibiko
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Many users mentioned that there is sometimes the need to open a file
which is encoded in e.g. Chinese Big5 or in Japanese Shift-JIS.
The TextMate manual recommends in respect to that topic to use the
UNIX command 'iconv'. It works perfectly, but if you have to open many
files of different encodings the typing of such commands will become a
bit uncomfortable.
To make it a bit easier I wrote with the Bundle Editor a new template
called openEncodedFile based on CocoaDialog's features.
Here is one way to use my suggestion:
- open the Bundle Editor
- Show all
- go to the folder 'TextMate' (or whatever)
- add a new template 'openEncodedFile' (or whatever)
Template data
- Extension: leave it empty
- Command(s):
# open CocoaDialog's file select menu
file=$(CocoaDialog fileselect \
--title "Open an encoded file" \
--with-directory $HOME/ \
)
# check for valid file
if [ -n "$file" ]; then
# open CocoaDialog's dropdown menu
# for more encodings add them to '--items'
# to list all possibile encodings use the Terminal with 'iconv -l'
res=$(CocoaDialog dropdown \
--title "Open an encoded file" \
--text "Choose the encoding:" \
??exit?onchange \
--button1 "Open" \
--button2 "Cancel" \
--items "BIG5" "EUC-TW" "GB2312" "SJIS" "EUC-JP" "KOI8-R" \
)
# if user canceled exit
[[ $( (tail -r <<<"$res") | tail -n1) == "2" ]] && \
exit_discard
res=$(tail -n1 <<<"$res")
# add more 'elif' according to '--items' if needed
if [ "$res" == 0 ]; then
ENC="BIG5"
elif [ "$res" == 1 ]; then
ENC="EUC-TW"
elif [ "$res" == 2 ]; then
ENC="GB2312"
elif [ "$res" == 3 ]; then
ENC="SJIS"
elif [ "$res" == 4 ]; then
ENC="EUC-JP"
elif [ "$res" == 5 ]; then
ENC="KOI8-R"
fi
# start conversion to UTF-8 and send the result as a new file back to TM
iconv -f "$ENC" -t utf-8 "$file" > "$TM_NEW_FILE"
fi
- Output: Insert as Text
- Activation: Key Equivalent shift+option+o (my suggestion)
- Scope: leave it empty
I've chosen a new template because the used keyboard short-cut is also
available if no document is open.
As you can see in the script you can add/edit encodings very easily.
(More details within the code)
If you start that bundle (shift+option+o) you will see a file choose
menu. Select your file and press ENTER or 'Open'. Then you will be
asked to input the right encoding. The available encodings are listed
in a drop-down menu. Select one encoding and press ENTER or 'Open'.
The script will convert your file according to the selected encoding
to utf-8. The result will be shown in a new document.
Hopefully the very tiny script is useful for others as well. Feedback
is highly welcomed.
Many greetings,
Hans-Jörg Bibiko
PS TODO: Include an automatical encoding detection. Hopefully coming soon ;)
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Well, I've been having quite a time of it with tab-triggered
commands. From looking through the many existing bundles, I'm not
surprised it took me this long to notice this bug(?), there are very
very few commands that use tab triggers.
The problem is that a tab-triggered command will empty the line that
I use the tab-trigger within when in fact the command is supposed to
replace or alter the line in some way, not delete it.
I first noticed the behavior when using Mike Mellor's GTD2 bundle and
at first thought that it was his scripts that weren't working on my
system. After some back and forth communication between Mike and I, I
was able to see that this problem happens with MOST commands that are
tab-triggered.... MOST but not ALL. I could understand all of them
not working, but most of the few that exist in the bundles I have
active don't work while one does.
Here's a list of the commands and their bundles:
GTD2:
delegate (python script)
wait (python script)
undo state change (python script)
done (python script)
Objective-C:
alloc (ruby script)
super (doesn't seem to, but haven't the time to layout test code)
(python script)
The one example that does work is...
Ruby:
word_wrap() (ruby script)
The only common thread I can see is the path to the executable at the
top of the shell script.
The ones that fail all are shell scripts in which they define the
path to the exec file at the top:
#!/usr/bin/env python
#!/usr/bin/env ruby
But then, there are other scripts that AREN'T tab-triggered and also
use shell scripts with the defined path that work.
I'm using TextMate Version 1.5.3 (1269) on OSX 10.4.8 on a 1GHz
PowerPC G4 powerbook.
Any help narrowing this problem down would be greatly appreciated.
Thanks
Mike
I know it's probably something obvious I'm not doing, but I'd really
like to be able to preview an HTML document in a project while
editing a linked CSS file. Every time I open a preview on the HTML
document and switch to the CSS file in my project, the web preview
closes. Is this normal?
I've been doing fine with using the "Refresh open browsers" command
and split off commands to shift-refresh firefox and exclusively
refresh Xylescope, but having the instant feedback in the web preview
would be great, especially when combined with the current ability to
pipe through your PHP installation.
Thanks,
Brett
OK -- I'm diving into the GTD2 bundle's way of doing GTD. Cool enough.
The URLs for the GTD Active View List seem broken. At least,
clicking 'em does not bring up the file/line as I would expect.
The URLs produced are of the form:
txmt://open/?url=file://personal&line=7
Clearly, the file path is incorrect.
b.bum
When editing a mail, double quoted blocks have this scope:
text.mail.markdown
text.html.markdown
meta.block-level.markdown
markup.quote.markdown
markup.quote.markdown
Shouldn't it be "markup.quote.double.markdown" or something?
Or is it possible to apply different colors to different quotation
levels like that?
Thanks
--
FredB
Hi all,
[apologies if this appears more than once; been having posting trouble]
guerom00 wrote:
> Hi there,
>
> This a feature request : I would like to be able
> to cancel a “Find in Project”.
> Because while TM searches, it basically freezes
> for any other actions...
>
> TIA :)
More generally, this brings up the question of why the system (not just
TM!) becomes unresponsive, and why the search is so slow (at least for
projects that include whole directory trees).
Yours,
Andrew
Version 1.5.3 (1215).
I have an Xcode project directory, which a TextMate project file
encompasses. The directory contains a "build" subdirectory. It would
be very undesirable to include that directory (and a couple of others,
such as .xclassmodels, also some binaries like a Stuffit archive) in
the TextMate project, as project-wide searches take much, much longer
when (I assume) the search interrogates all the files in the build tree.
So I select the build folder in the project list and press backspace.
TextMate asks if I want a remove-from-project or a delete-file.
Remove, please.
Shortly thereafter (it may be related to deactivating and reselecting
TextMate), the build folder appears in the list again. Grz.
I have double-checked that I am dealing with a TextMate project file,
and not a directory window.
Some of the re-added files and folders have been modified while
TextMate is running; most have not.
I had used a directory window before switching to a project.
I originally populated the project by dragging the Xcode project
directory into the file list.
What am I missing? Or what is TextMate missing? It may be my problem,
as searching for "project file reincludes folders" turns up nothing in
a list-archive search.
— F
Thanks Allan.
The code works perfectly! I've tried to insert a variable inside...
<${1:ul}>
${TM_SELECTED_TEXT/(.+)(?:\n(.+))?/ <li class="${3:odd}">$1<\/li>(?2:
\n <li>$2<\/li>)/g}
</$1>
...and this is the result...
<ul>
<li class="${3:odd}">dfadfadfadfadfad</li>
<li>fadfadfadfdaf</li>
<li class="${3:odd}">afdfadfdafd</li>
</ul>
How can we adjust the class to be the next tab stop with a default? I
also adjusted your code to allow for a clean indentation of the li
elsments.
Thanks for the help. :)