Hi Keita, Ikumi Keita <[email protected]> writes:
>>>>>> Arash Esbati <[email protected]> writes: > > You are always keen about new features about LaTeX! Thanks for your response. I think it is important for AUCTeX to keep up with LaTeX development. >> (TeX-read-hook nil) > > It works as expected. Thanks! > Don't we need shipout hooks as well? I see > ,---- > | 2.8.4 > | Hooks provided \shipout operations > | There are several hooks and mechanisms added to LATEX’s process of > generating pages. > | These are documented in ltshipout-doc.pdf or with code in > ltshipout-code.pdf. > `---- > in lthooks-doc.pdf and ltshipout-doc.pdf seems to provide the following > hooks: > shipout/before > shipout/foreground > shipout/background > shipout/firstpage > shipout/lastpage Indeed, they were missing, also the ones coming from ltpara-doc.pdf, namely: para/before para/begin para/end para/after >> ;; file/(before|after)/<file-name.xxx> where <file-name> is >> ;; optional and must be with extension >> ((string-match "\\`file" hook) > > Maybe `string-prefix-p' suits slightly better than `string-match', but > of course they have practically no difference. After thinking about it, I have a preference to check the hook against a list like this: (member hook '("file/before" "file/after") I think this is less error prone if the name of other hooks starts with `file'. >> (setq result (mapconcat #'identity >> `(,hook ,name ,where) >> "/")) > > I think > (concat hook "/" name "/" where) > is equivalent to that `mapconcat' call and seems more simple and > natural, IMHO. Indeed, makes sense. My next iteration 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 (eq TeX-arg-input-file-search 'ask) (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
