Download
(defun wuxch-go-to-char-forward()
""
(interactive)
(do-wuxch-go-to-char t)
)
(defun wuxch-go-to-char-backward()
""
(interactive)
(do-wuxch-go-to-char nil)
)
(defun do-wuxch-go-to-char (direction)
"goto the point which char is same as user input. Set mark word away from point
press up/down key to change direction
press /control-g/ /enter/ to terminate, which /enter/ leave mark active "
(push-mark)
(let ((input)(end-of-input nil)(leave-mark-active t))
(while (not end-of-input)
(progn
(setq input (read-key-sequence (if direction "input char(forward):" "input char(backward):" ) ))
(cond
((or (equal input "\C-m") (equal input "\C-j"))
(progn
(setq leave-mark-active t)
(setq end-of-input t)))
((equal input "\C-g")
(progn
(setq leave-mark-active nil)
(setq end-of-input t)))
((equal input [down])
(progn
(setq direction t)))
((equal input [up])
(progn
(setq direction nil)))
((wuxch-go-to-char-judge-legal-char input)
(progn
(if direction
(wuxch-search-forward-char-and-mark-word input)
(wuxch-search-backward-char-and-mark-word input))
))
(t
(progn
))
)
)
)
(if (not leave-mark-active)
(deactivate-mark))
)
(message "Done!")
)
(defun wuxch-go-to-char-judge-legal-char( str )
"Judge if the first char of str is legal"
(let ((c (string-to-char str)))
(or
(and (<= c (string-to-char "z")) (>= c (string-to-char "a")))
(and (<= c (string-to-char "Z")) (>= c (string-to-char "A")))
(and (<= c (string-to-char "9")) (>= c (string-to-char "0")))
(or (= c (string-to-char "_"))
(= c (string-to-char "-"))
(= c (string-to-char "+"))
(= c (string-to-char "*")) )
(or (= c (string-to-char "("))
(= c (string-to-char ")"))
(= c (string-to-char "="))
(= c (string-to-char "'")) )
(or (= c (string-to-char "["))
(= c (string-to-char "]"))
(= c (string-to-char "{"))
(= c (string-to-char "}")) )
(or (= c (string-to-char "."))
(= c (string-to-char ","))
(= c (string-to-char ";"))
(= c (string-to-char ":")) )
)
)
)
(defun wuxch-search-forward-char-and-mark-word( input )
""
(forward-char 1)
(if (search-forward input nil t 1)
(progn
(backward-char 1)
(mark-word)
)
(progn
(message "search-forward,not found char:%s" input)
(backward-char 1)))
)
(defun wuxch-search-backward-char-and-mark-word( input )
""
(if (search-backward input nil t 1)
(progn
(mark-word)
)
(progn
(message "search-backward,not found char:%s" input)))
)
(global-set-key [(control \
(global-set-key [(control \
(global-set-key [(control \')] 'ignore)
(global-set-key [(control \')] 'wuxch-go-to-char-backward)
(provide 'wuxch-goto-char)