将变量名称并入“dolist”循环并更改其值 [英] Incorporate variable name into `dolist` cycle and change its value

查看:232
本文介绍了将变量名称并入“dolist”循环并更改其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将缓冲区本地变量的名称并入 dolist 循环中,并更改缓冲区本地变量。 setq setq-local 拒绝我尝试过的所有变量名称变体。在 dolist 循环中,变量名称为(car(car(cdr test)))

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.

此项目是相关的两(2)最近我的线程,但我相信这是一个有点独特的问题。相关主题如下:如何使用`setcdr`与buffer-局部变量 如何使用cons单元格来定义和后来用`dolist` 删除叠加层

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)

我也尝试修改列表使用字符串,例如'(variable-one,variable-one)

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

以下是测试代码

(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 (2014年8月26日):以下修订是基于这个线程中的每个人 - 非常感谢!:)今天晚些时候,我仍然需要对多个缓冲区进行一些缓冲区本地测试,但是论坛参与者的建议似乎与下面的测试大纲一起工作。


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) ))


推荐答案

我不知道你的意思是dolist循环。

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

你的问题的根源是 setq 是一种特殊的形式,第一个参数不需要引用 - 这就是q的意思。

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.

您要使用设置

这篇关于将变量名称并入“dolist”循环并更改其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆