emacsの正規表現の置換は置換するときに計算できて賢い感じ
一致した箇所を先頭を大文字にする関数に渡すことができます。
;;置換前 foo bar baz ;;置換後 Foo Bar Baz
置換前のfooからbazまでを選択してから下記のコマンドを実行します。
M-x replace-regexp Replace regexp: \(\w+\) Replace regexp with: \,(capitalize \1)
;;置換前 <h1>foo</h1> <h2>bar</h2> <h3>baz</h3> ;;置換後 <h2>foo</h2> <h3>bar</h3> <h4>baz</h4>
同様に選択して、下記のコマンドを実行します。
M-x replace-regexp Replace regexp: <\(/?\)h\([0-9]\)> Replace regexp with: <\1h\,(1+ \#2)>
http://dminor11th.blogspot.jp/2011/02/emacslisp.html
(defun camel-to-snake (s &optional do-upcase) (let ((case-fold-search nil)) (funcall (if do-upcase 'upcase 'downcase)
(replace-regexp-in-string "\\([A-Z]\\)" "_\\1" (concat (downcase (substring s 0 1)) (substring s 1)))))) (defun snake-to-camel (s &optional capitalize) (let ((case-fold-search nil)) (replace-regexp-in-string "_\\([a-zA-Z]\\)" (lambda (s2) (upcase (substring s2 1))) (concat (if capitalize "_" "") s))))
http://recyclebin5385.blog13.fc2.com/blog-category-4.html
(defun get-select-text () (interactive) (setq selected-text (buffer-substring (region-beginning) (region-end))) (insert selected-text))