Hi Keita, Ikumi Keita <[email protected]> writes:
>>>>>> Arash Esbati <[email protected]> writes: >> My next iteration looks like this: >> (defvar TeX-global-input-files-with-extension nil >> "List of the non-local TeX input files with extension. >> Initialized once at the first time you prompt for an input file >> inside a file hook command. May be reset with >> `\\[universal-argument] \\[TeX-normal-mode]'.") > > This doc string results in: > [...] > inside a file hook command. May be reset with > ‘C-u C-c C-n’. > when I do "C-h v TeX-global-input-files-with-extension". I think it > looks nicer without line break between "with" and "`C-u". Ok, I would then move the complete sentence into next line: (defvar TeX-global-input-files-with-extension nil "List of the non-local TeX input files with extension. Initialized once at the first time you prompt for an input file inside a file hook command. May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") >> (search (if (eq TeX-arg-input-file-search 'ask) >> (not (y-or-n-p "Find file yourself? ")) >> TeX-arg-input-file-search)) > > When `TeX-arg-input-file-search' is `ask', the user is always asked > y-or-n question even when "cmd" or "env" hook is entered. So call to > this code should be deferred. Argh, thanks for catching this. I think I can cure this by adding a check like this: (search (if (and (eq TeX-arg-input-file-search 'ask) (member hook '("file/before" "file/after" "include/before" "include/end" "include/after" "class/before" "class/after" "package/before" "package/after"))) (not (y-or-n-p "Find file yourself? ")) TeX-arg-input-file-search)) The hopefully final version looks like this: --8<---------------cut here---------------start------------->8--- (defvar TeX-global-input-files-with-extension nil "List of the non-local TeX input files with extension. Initialized once at the first time you prompt for an input file inside a file hook command. May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") (defun TeX-read-hook (_optional) "Read a LaTeX hook." (let* ((hook (completing-read (TeX-argument-prompt nil nil "Hook") '("cmd" "env" ;; From ltfilehook-doc.pdf "file/before" "file/after" "include/before" "include/end" "include/after" "class/before" "class/after" "package/before" "package/after" ;; From lthooks-doc.pdf "begindocument" "begindocument/before" "begindocument/end" "enddocument" "enddocument/afterlastpage" "enddocument/afteraux" "enddocument/info" "enddocument/end" "rmfamily" "sffamily" "ttfamily" "normalfont" "bfseries" "bfseries/defaults" "mdseries" "mdseries/defaults" ;; From ltshipout-doc.pdf "shipout/before" "shipout/after" "shipout/foreground" "shipout/background" "shipout/firstpage" "shipout/lastpage" ;; From ltpara-doc.pdf "para/before" "para/begin" "para/end" "para/after"))) (func (lambda () (completing-read (TeX-argument-prompt nil nil "Where") (if (string= hook "cmd") '("after" "before") '("before" "begin" "end" "after"))))) (search (if (and (eq TeX-arg-input-file-search 'ask) (member hook '("file/before" "file/after" "include/before" "include/end" "include/after" "class/before" "class/after" "package/before" "package/after"))) (not (y-or-n-p "Find file yourself? ")) TeX-arg-input-file-search)) name where files result) (cond ((string= hook "cmd") ;; cmd/<name>/<where> (setq name (completing-read (TeX-argument-prompt nil nil "Command") (TeX-symbol-list))) (setq where (funcall func))) ;; env/<name>/<where> ((string= hook "env") (setq name (completing-read (TeX-argument-prompt nil nil "Environment") (LaTeX-environment-list))) (setq where (funcall func))) ;; file/(before|after)/<file-name.xxx> where <file-name> is ;; optional and must be with extension ((member hook '("file/before" "file/after")) (if search (unless TeX-global-input-files-with-extension (setq TeX-global-input-files-with-extension (prog2 (message "Searching for files...") (mapcar #'list (TeX-search-files-by-type 'texinputs 'global t nil)) (message "Searching for files...done"))))) (setq name (completing-read (TeX-argument-prompt t nil "File") TeX-global-input-files-with-extension))) ;; include/(before|after|end)/<file-name> where <file-name> ;; is optional ((member hook '("include/before" "include/end" "include/after")) (if search (setq files (prog2 (message "Searching for files...") (TeX-search-files-by-type 'texinputs 'local t t) (message "Searching for files...done")))) (setq name (completing-read (TeX-argument-prompt t nil "File") files))) ;; class/(before|after)/<doc-class> where <doc-class> is ;; optional ((member hook '("class/before" "class/after")) (let* ((TeX-file-extensions '("cls"))) (unless LaTeX-global-class-files (setq LaTeX-global-class-files (if search (prog2 (message "Searching for LaTeX classes...") (mapcar #'list (TeX-search-files-by-type 'texinputs 'global t t)) (message "Searching for LaTeX classes...done")) LaTeX-style-list)))) (setq name (completing-read (TeX-argument-prompt t nil "Document class") LaTeX-global-class-files))) ;; package/(before|after)/<pack-name> where ;; <pack-name> is optional ((member hook '("package/before" "package/after")) (let* ((TeX-file-extensions '("sty"))) (unless LaTeX-global-package-files (setq LaTeX-global-package-files (if search (prog2 (message "Searching for LaTeX packages...") (mapcar #'list (TeX-search-files-by-type 'texinputs 'global t t)) (message "Searching for LaTeX packages...done")))))) (setq name (completing-read (TeX-argument-prompt t nil "Package") LaTeX-global-package-files))) ;; User specific input for the hook or others, do nothing ;; and just insert `hook' later: (t nil)) (if (member hook '("cmd" "env")) (setq result (concat hook "/" name "/" where)) (push hook result) (when (and name (not (string= name ""))) (push name result)) (setq result (mapconcat #'identity (reverse result) "/"))) (insert "\n" "\\AddToHook{" result "}"))) --8<---------------cut here---------------end--------------->8--- Best, Arash
