我正在使用一个使用mapcar的函数将(简单)函数应用于列表的所有成员,如下所示:
(mapcar 'my-concat-function '(
"/path/one.php"
"/path/two.php"))
但我想使用directory-files
生成文件列表并对其进行过滤,如下所示:
(mapcar 'my-concat-function '(
(directory-files "/path/" nil "\\.php$")))
但我总是得到一个
find-file-noselect: Wrong type argument: stringp, (directory-files "/path/" nil "\\.php$")
当我评估时
(directory-files "/path/" nil "\\.php$")
返回
("one.php" "two.php" "three.php" ...)
(我没有添加“...”; Emacs确实如此。无论列表的大小如何,它似乎总是以“......”结束。)
问题:
如何格式化directory-files
的输出以使其产生mapcar所需的内容,单个原子列表,我真的不知道如何调用此形式:
"one.php" "two.php" "three.php"
没有括号,没有那些奇怪的“......”?
修改
当我尝试建议的表格时(谢谢你们)引用的函数作为mapcar的第一个arg不起作用(regexp找不到任何东西,所有文件最终都在空(?)缓冲区中打开):( < / p>
这是完整的代码,非常感谢你的帮助,这很奇怪,这个函数花了很少的时间来编写,现在我已经被阻止了几个小时就这个简单的列表问题,arg。
(defun px-bpm-parse (fname)
"Extract elements. Basic Project Management."
(setq in-buf (set-buffer (find-file fname)))
(setq u1 '())
(setq u2 '())
(setq u3 '())
(setq project-dir "/var/www/html/microlabel.git/")
(beginning-of-buffer)
(while
(re-search-forward "^.*<link.*href=\"\\([^\"]+\\)\".*rel=\"stylesheet\"" nil t)
(when (match-string 0)
(setq url (match-string 1) )
(setq u3 (cons (concat "[[file:" project-dir url "][" url "]]\n") u3))))
(beginning-of-buffer)
(while
(re-search-forward "^.*<a.*href=\"\\([^\"]+\\)\"[^>]+>\\([^<]+\\)</a>" nil t)
(when (match-string 0)
(setq url (match-string 1) )
(setq title (match-string 2) )
(setq u1 (cons (concat "[[file:" project-dir url "][" title "]]\n") u1))))
(beginning-of-buffer)
(while
(re-search-forward "^.*<script.*src=\"\\([^\"]+\\)\"" nil t)
(when (match-string 0)
(setq url (match-string 1) )
(setq u2 (cons (concat "[[file:" project-dir url "][" url "]]\n") u2))))
(beginning-of-buffer)
(progn
(with-current-buffer "BPM.org"
(insert "** File: ")
;; (org-insert-link &optional COMPLETE-FILE LINK-LOCATION DEFAULT-DESCRIPTION)
(insert fname)
(insert "\n*** HREF Links (by name)\n")
(mapcar 'insert u1)
(insert "\n*** SCRIPT Links\n")
(mapcar 'insert u2)
(insert "\n*** CSS Links\n")
(mapcar 'insert u3)
(insert "\n\n"))
(switch-to-buffer "BPM.org")
(org-mode)))
(defun px-bpm ()
;; (defun px-bpm (prj-root)
"List all links"
(interactive)
;; (interactive "sEnter project root directory ")
(progn
(with-current-buffer (get-buffer-create "BPM.org")
(insert "* File dependencies\n\n"))
;; (mapcar 'px-bpm-parse '(
;; "/var/www/html/microlabel.git/add.php"
;; ))
(mapcar 'px-bpm-parse (directory-files "/var/www/html/microlabel.git/" nil "\\.php$"))
))
答案 0 :(得分:1)
当您评估表单并查看表单(x y z ...)
的结果时,它会以这种方式打印,因为输出很长。结果实际上是您期望的列表。例如,
(list 1 2 3 4 5 6 7 8 9 10 11 12 13)
;=> (1 2 3 4 5 6 7 8 9 10 11 12 ...)
然而,列表的最后一个元素应该是:
(last (list 1 2 3 4 5 6 7 8 9 10 11 12 13))
;=> (13)
由于(directory-files "/path/" nil "\\.php$")
返回一个列表而mapcar的第二个参数应该是一个列表,你可以将它作为第二个参数:
(mapcar 'my-concat-function (directory-files "/path/" nil "\\.php$"))