Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/emacs/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs Elisp:如何缩短此函数_Emacs_Macros_Elisp - Fatal编程技术网

Emacs Elisp:如何缩短此函数

Emacs Elisp:如何缩短此函数,emacs,macros,elisp,Emacs,Macros,Elisp,我正在实现一个插件,它可以记住很多项目类型。例如:角形、流星、余烬、轨道 并使用键控参数。该函数使用提供的键和值创建一个哈希表,并将该哈希表分配给另一个哈希表 代码如下: (defun jst-remember-project-type (type &rest args) "Let JST remember another project type." (let (label value testing-framework spec-dir config-

我正在实现一个插件,它可以记住很多项目类型。例如:角形、流星、余烬、轨道

并使用键控参数。该函数使用提供的键和值创建一个哈希表,并将该哈希表分配给另一个哈希表

代码如下:

    (defun jst-remember-project-type (type &rest args)
      "Let JST remember another project type."
      (let (label value testing-framework spec-dir config-file source-dir
                  command-ci command-browser spec-to-target target-to-spec
                  dominating-files browser-url table)
        (while (not (= 0 (length args)))
          (setq label (pop args))
          (setq value (pop args))
          (and (equal :testing-framework label) (setq testing-framework value))
          (and (equal :spec-dir label) (setq spec-dir value))
          (and (equal :source-dir label) (setq source-dir value))
          (and (equal :config-file label) (setq config-file value))
          (and (equal :command-ci label) (setq command-ci value))
          (and (equal :command-browser label) (setq command-browser value))
          (and (equal :browser-url label) (setq browser-url value))
          (and (equal :spec-to-target label) (setq spec-to-target value))
          (and (equal :target-to-spec label) (setq target-to-spec value))
          (and (equal :dominating-files label) (setq dominating-files value)))
        (if (gethash type jst-known-project-types)
            (error "Redefined JST project type.")
          (setq table (make-hash-table :test 'equal))
          (puthash :testing-framework testing-framework table)
          (puthash :spec-dir spec-dir table)
          (puthash :config-file config-file table)
          (puthash :source-dir spec-dir table)
          (puthash :command-ci command-ci table)
          (puthash :command-browser command-browser table)
          (puthash :spec-to-target spec-to-target table)
          (puthash :target-to-spec target-to-spec table)
          (puthash :dominating-files dominating-files table)
          (puthash :browser-url browser-url table)
          (puthash type table jst-known-project-types))) nil)
我有很多像这样的冗余函数。我希望这些函数由宏自动生成

实际上,只需要一个键列表和一个表。其他一切都可以生成。但是我不知道如何编写宏

    (defmacro jst-remember-keyed (keys table)
      "This macro helps with jst-remember functions."
      (let (label value QUESTION HERE keys)))
如何轻松地从:symbol转换变量和从变量转换:symbol

    (make-symbol "fuck")
    fuck ;; Error occurs

    (let (((make-symbol "fuck") "Diao"))
      (message fuck)
      ) ;; Error occurs
非常感谢

未经测试:

(require 'cl)
(defun jst-remember-project-type (type &rest args)
  "Let JST remember another project type."
  (if (gethash type jst-known-project-types)
      (error "Redefined JST project type.""")
    (let ((table (make-hash-table :test #'equal)))
      (loop for (label value) on args by #'cddr
            do (puthash label value table))
      (puthash type table jst-known-project-types))))

谢谢,我正在努力。#是什么意思?#是
函数
的缩写,严格来说,它在elisp中不是必需的,但它向代码的人类读者传达了意义,因此仍然是一个有值信号,表示您考虑的是绑定到符号的函数,而不是符号本身。