2010-06-29

Emacsで改行を含む置換とxml-modeのindent-region

実際には6月30日のネタだけど長くなるのでずらして書くなり。

minibuffer では \n ではなく C-q C-j

Emacs で改行コードを含む置換をやったことがなかったか避けてきたらしく、今まで知らなかった。

調べると以下のように書かれている。

8.2 Editing in the Minibuffer

The minibuffer is an Emacs buffer, albeit a peculiar one, and ""the usual Emacs commands are available for editing the argument ""text. (The prompt, however, is read-only, and cannot be changed.)

Since <RET> in the minibuffer is defined to exit the minibuffer, ""you can't use it to insert a newline in the minibuffer. To do ""that, type C-o or C-q C-j. (The newline character is really the ""ASCII character control-J.)

Minibuffer Edit - GNU Emacs Manual

てっきり \n や \\n で改行を表現するのかと思っていたけど、ハードタブを入力するのと同じく C-q に続けてコードそのものを入力するらしい。

ちなみに普段編集している際には Enter も C-j も C-m も同じように改行してくれるけど、

C-mCR
C-jLF

は厳密に区別されるので注意。また自分の環境では C-q RET は CR が入力された。これはもしかしたら設定で変更できるかもしれないけど、C-q C-j で覚えてしまう方が楽な気がする。

ところで、上記以外のコントロールコードも何がどれに割り当てられてるか知らないな…。と思ったらここにあった。

Control character - Wikipedia, the free encyclopedia

これだけ分かればとりあえず足りる、のかな?

xml-mode の indent には改行が必要

なんで改行コードを含む置換をしたくなったかと言うと、OOo の template の XML ファイルを編集する際に indent がなくて見にくかったから。Emacs の xml-mode で indent できるよって教えてもらったけどできなかったので、改行コードが要るのかと思って試してみたらこれが bingo.

具体的には

replace-string で > を >C-qC-j に置換

した。

About

例によって個人のなんちゃらです

Recent Posts

Categories

Tool 日々 Web Biz Net Apple MS ことば News Unix howto Food PHP Movie Edu Community Book Security Text TV Perl Ruby Music Pdoc 生き方 RDoc ViewCVS CVS Rsync Disk Mail FreeBSD Cygwin PDF Photo Zebedee Debian OSX Comic Cron Sysadmin Font Analog iCal Sunbird DNS Linux Wiki Emacs Thunderbird Sitecopy Terminal Drawing tDiary AppleScript Life Money Omni PukiWiki Xen XREA Zsh Screen CASL Firefox Fink zsh haXe Ecmascript PATH_INFO SQLite PEAR Lighttpd FastCGI Subversion au prototype.js jsUnit Apache Trac Template Java Rhino Mochikit Feed Bloglines CSS del.icio.us SBS qwikWeb gettext Ajax JSDoc Rails HTML CHM EPWING NDTP EB IE CLI ck ThinkPad Toy WSH RFC readline rlwrap ImageMagick epeg Frenzy sysprep Ubuntu MeCab DTP ERD DBMS eclipse Eclipse Awk RD Diigo XAMPP RubyGems PHPDoc iCab DOM YAML Camino Geekmonkey w3m Scheme Gauche Lisp JSAN Google VMware DSL SLAX Safari Markdown Textile IRC Jabber Fastladder MacPorts LLSpirit CPAN Mozilla Twitter OpenFL Rswatch ITS NTP GUI Pragger Yapra XML Mobile Git Study JSON VirtualBox Samba Pear Growl Mercurial Rack Capistrano Rake Win RSS Mechanize Sitemaps Android JavaScript Python RTM OOo iPod Yahoo Unicode Github iTunes God SBM friendfeed Friendfeed HokuUn Sinatra TDD Test Project Evernote iPad Geohash Location Map Search Simplenote Image WebKit RSpec Phone CSV WiMAX USB Chrome RubyKaigi RubyKaigi2011 Space CoffeeScript Nokogiri Hpricot Rubygems jQuery Node GTD CI UX Design VCS Kanazawa.rb Kindle Amazon Agile Vagrant Chef Windows Composer Dotenv PaaS Itamae SaaS Docker Swagger Grape WebAPI Microservices OmniAuth HTTP 分析基盤 CDN Terraform IaaS HCL Webpack Vue.js BigQuery Middleman CMS AWS PNG Laravel Selenium OAuth OpenAPI GitHub UML GCP TypeScript SQL Hanami Document SVG AsciiDoc Pandoc DocBook Develop Jekyll macOS Node.js Vite Heroku Transformer AI Data Cloud Wasm