Q: How to programmatically increment several numeric keys of a hash-table.
Background:
I am working on a modificion of speedbar to support the concept of speedbar-get-marked-files
-- speedbar -- mark/unmark directories/files -- `speedbar-get-marked-files` I have setup a hash-table that consists of buffer line numbers for the keys, and the values are absolute filenames or directories.
When clicking on a +
sign to expand directories, speedbar inserts additional files and directories underneath the expanded node. It is at this point that the hash-table needs to be modified, since puthash
replaces existing entries. Programmatically, I already know how many new lines will be inserted.
Example:
A buffer contains 9 lines (in this case all directories), with a corresponding hash-table.
1 "/usr/"
2 "/usr/bin"
3 "/usr/include"
4 "/usr/lib"
5 "/usr/libexec"
6 "/usr/local"
7 "/usr/man"
8 "/usr/sbin"
9 "/usr/share"
We click on the expandable directory /usr/lib
and programmatically we know that 8 new directories and 27 new files will be inserted. Therefore, a total of 35 new lines will be added underneath line 4 -- the previous hash-table entries of 5, 6, 7, 8 and 9 all need to be renumbered by adding 35 to each one. The new hash-table should become:
1 "/usr/"
2 "/usr/bin"
3 "/usr/include"
4 "/usr/lib"
40 "/usr/libexec"
41 "/usr/local"
42 "/usr/man"
43 "/usr/sbin"
44 "/usr/share"