[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elisp] easy-to-use bookmarks functionality
From: |
alex_sv |
Subject: |
[elisp] easy-to-use bookmarks functionality |
Date: |
Tue, 04 May 2010 15:42:34 -0000 |
User-agent: |
G2/1.0 |
Hi all,
For my own needs I wrote a small function that provides easy-to-use
bookmarking: C-[1..9] - sets "bookmark" (in fact remembers point in
the corresponding register), M-[1..9] - jumps to the corresponding
position.
Now I would like to see whether it could be implemented in a less
verbose and more intelligent way.
The flaws of my function are:
1) I don't know how to construct "key sequence" object from the
strings part, e.g. get "\C-1" sequence from the source strings "C-"
and "1", so I wrote local helper function - get-key-code that accepts
key sequence strings and creates the corresponding key sequence using
eval form with a call to kbd.
2) local-set-key function can't use locally defined closures so I
constructed corresponding lambda using append/list/quote facility that
looks quite ugly.
Here is the function:
(defun bind-navigation-command-to-numkeys ()
"provides easy-to-use bookmarking functionality - binds navigation
commands to
C-{index}, M-{index} keys, where index is a numeric key from 1 to 9"
(let (
;; helper function that returns key sequence object that
;; corresponds to the concatenated string sequence given
(get-key-code (lambda (&rest key-sequence-str-list)
(eval (let ((key-sequence
(mapconcat
(function
(lambda (c) c))
key-sequence-str-list "")))
(append (list 'kbd)
(list key-sequence)))))))
;; assign handlers for C/M-[1..9] keys
(loop for key-index from 1 to 9 do
(let ((key-str (int-to-string key-index)))
;; save point
(local-set-key (funcall get-key-code "C-" key-str)
;; handler form
(list 'lambda '()
'(interactive)
(list 'point-to-register key-index)))
;; goto saved point
(local-set-key (funcall get-key-code "M-" key-str)
;; handler form
(list 'lambda '()
'(interactive)
(list 'register-to-point key-index)))))))
comments appreciated :)
- [elisp] easy-to-use bookmarks functionality,
alex_sv <=