Incorporate variable name into `dolist` cycle and

2019-09-06 09:01发布

I am trying to incorporate the name of a buffer-local variable into the dolist cycle, and change the value of that buffer-local variable. setq and setq-local reject all of the variable name variations that I have tried. In the dolist cycle, the variable name is (car (car (cdr test))).

The same variable name will be used in more than one buffer, with each buffer having a different value.

This project is related two (2) other recent threads of mine, but I believe this is a somewhat unique issue. The related threads are as follows:  How to use `setcdr` with buffer-local variables and How to use a cons cell to define and later remove overlays with `dolist`

I have tried all of the following, and a few other variations, without success:

(setq (car (car (cdr test))) newlist)

(setq var newlist)

(setq (make-symbol (car (car (cdr test)))) newlist)

(setq (intern (car (car (cdr test)))) newlist)

I have also tried modifying the list to use a string, e.g., '("variable-one" ,variable-one)


Here is the test code:

(defvar variable-one '(a t))

(make-variable-buffer-local 'variable-one)

(defvar variable-two '(c t))

(make-variable-buffer-local 'variable-two)

(defvar variable-three '(e t))

(make-variable-buffer-local 'variable-three)

(dolist (test `(
    '(variable-one ,variable-one)
    '(variable-two ,variable-two)
    '(variable-three ,variable-three) ))
  (let* (
      (var (car (car (cdr test))))
      (newlist (copy-list (car (cdr (car (cdr test)))))) )
    (setcdr newlist nil)
    (message "var: %s | newlist: %s" var newlist)
    ;; (setq (car (car (cdr test))) newlist)
  ))

EDIT (August 26, 2014):  The following revision is based upon the helpful suggestions provided by everyone in this thread -- greatly appreciated! :) I still need to conduct some buffer-local tests with multiple buffers later on today, but the suggestions made by the forum participants seem to work with the test outline below.

(defvar variable-one '(a t))

(make-variable-buffer-local 'variable-one)

(defvar variable-two '(c t))

(make-variable-buffer-local 'variable-two)

(defvar variable-three '(e t))

(make-variable-buffer-local 'variable-three)

(dolist (test `(
    (variable-one ,variable-one)
    (variable-two ,variable-two)
    (variable-three ,variable-three) ))
  (let* (
      (var (car test))
      (newlist (copy-list (car (cdr test)))) )
    (setcdr newlist nil)
    (message "var: %s | newlist: %s" var newlist)
    (set (car test) newlist) ))

标签: emacs elisp
1条回答
手持菜刀,她持情操
2楼-- · 2019-09-06 09:46

I don't know what you mean by the "dolist cycle".

The root of your problem is that setq is a special form. The first argument doesn't need to be quoted -- that is what the "q" means.

You want to use set instead.

查看更多
登录 后发表回答