0

Q:  Is there a way to create one cache that consists of one cons cell and two hash tables? If so, how, please. If not, what is the best way to handle this scenario?

Background:

I'm working on a new feature for speedbar that creates a cache for:

nth 0:  a cons cell -- i.e., (cons speedbar-shown-directories (buffer-string))

nth 1:  a hash table [use line number to find absolute file name]

nth 2:  a hash table [use absolute file name to find line number].

The cache is speedbar-full-text-cache. I thought it would be handy to create a list of three elements -- the regular last open directory is saved in its entirety for ultra-fast switching for the first element (i.e., nth 0), and then I wanted to add two hash tables. So the thought was to create something like:

STEP 1:

(setq speedbar-full-text-cache
  (list (cons speedbar-shown-directories (buffer-string))))

STEP 2:  Try to append two hash tables.

(setq speedbar-full-text-cache
  (append speedbar-full-text-cache
    speedbar-line-to-node-table speedbar-node-to-line-table))

RESULT:  Debugger entered--Lisp error: (wrong-type-argument sequencep #s(hash-table size 97 test eql rehash-size 1.5 rehash-threshold 0.8 data . . .

Malabarba
  • 22,878
  • 6
  • 78
  • 163
lawlist
  • 18,826
  • 5
  • 37
  • 118

2 Answers2

4

append wants sequences and you gave it a cons cell and two hash tables, which is why you get an error. If you want to appends sequences, give it sequences : (append (list (cons ...)) (list hashtable1 hashtable2)) will do what you expected. But now of course it's easier and more efficient to just write (list (cons ...) hashtable1 hashtable2) as suggested in Drew's answer.

YoungFrog
  • 3,496
  • 15
  • 27
2

You question seems too broad. For the part of it that is specific, it seems unclear. Is this really all you are asking for?

(setq speedbar-full-text-cache
      (list (cons speedbar-shown-directories (buffer-string))
            speedbar-line-to-node-table
            speedbar-node-to-line-table))

Please pose as specific a question as you can, as opposed to "what is the best way to handle this scenario?" (for a vague scenario).

Drew
  • 75,699
  • 9
  • 109
  • 225