;-*- coding: utf-8 -*- ; some elisp string replacement functions ; used for regex replace operations ; 2007-06 ; Xah Lee ; ∑ http://xahlee.org/ (defun wikipedia-link-replacement () "Returns a canonical form of Wikipedia link from a regex match. This function is used for query-replace-regexp, to turn the following forms of links: event Middle_distance↗ Middle_distance_track_event↗ Sapir-Whorf_Hypothesis↗ into a cannonical form. Basically, the link text needs to have “_” replaced by space, and should have a “↗” at the end. Also, it shouldn't match links that's already in canonical form, nor matching non-wikipedia link texts. The regex to be used for this function is: \\(\\([-.A-Za-z0-9]+_\\)+[-.A-Za-z0-9]+ ?↗*\\) To use a function in query-replace-regexp, do “\\,(wikipedia-link-replacement)”. ." (let (langCode articlePath linkText linkText2 returnText) (setq langCode (buffer-substring (match-beginning 1) (match-end 1))) (setq articlePath (buffer-substring (match-beginning 2) (match-end 2))) (setq linkText (buffer-substring (match-beginning 3) (match-end 3))) (setq linkText2 (concat (replace-regexp-in-string "_" " " articlePath) "↗")) (setq returnText (concat "" linkText2 "" )) returnText ) ) (defun get-html-h1 () "Returns the current buffer's first

tag content. This function is used to get a set of HTML page's tag content in sync with the <h1> tag content. This function is used for dired-do-query-replace-regex. The search regex should be: <title>\([^<]+\) The replace string should be: \,(get-html-h1)" (interactive) (let (pos1 pos2) ; move to the beginning ; search for

, get position ; search for

, get position ; get the text between positions (save-excursion (goto-char (point-min)) (search-forward "

" nil t) (setq pos1 (point)) (search-forward "

" nil t) (search-backward "" nil t) (setq pos2 (point)) ) (buffer-substring-no-properties pos1 pos2) ) )