Как вставить * .tex-шаблоны в Emacs-буфер с помощью minibuffer-choose.el?

649
Keks Dose

Несколько недель назад я нашел этот ответ на https://tex.stackexchange.com/questions/2110/most-significant-reasons-that-led-%20us-to-latex/2144#2144 на tex.stackexchange.com.

«Leo2007» описывает, как вставить * .tex-шаблоны в буфер Emacs. Я не мог выяснить, как заставить это работать и решил спросить в списке рассылки autex, но не получил ответа в течение трех недель. Так что, может быть, вы можете помочь мне:

«Leo2007» представил файл minibuffer-choose.el, позволяющий быстро вставить шаблон в документ. Перейдите по ссылке Nr. 1 выше, и вы увидите довольно убедительную картину.

К сожалению, я не понимаю, как его использовать. Я получил файл minibuffer-choose.elотсюда: http://paste.lisp.org/display/113728 (я добавил его ниже).

Я сделал байтовую компиляцию, поместил ее туда, где ее мог найти emacs, и добавил 3 строки в мой .emacs-файл:

(require 'minibuffer-choose) (let ((files (directory-files "~/Emacs/Vorlagen" t "[a-z]+"))) (minibuffer-choose "Choose: " files 'file-name-nondirectory nil 'alpha))  But how do I use it?  Alexander  %%%%%%%%%%%%%%%%%%%%%%  ;;; minibuffer-choose.el --- Choose from Minibuffer  ;; Copyright (C) 2010 Leo  ;; Author: Leo ;; Keywords: tools, extensions  ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version.  ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details.  ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>.  ;;; Commentary:  ;; This is a programming facility allowing presenting a fixed set of ;; choices in the minibuffer with shortcut keys to select each.  ;;; Code: (eval-when-compile (require 'cl))  (defface minibuffer-choose-highlight '((((class color) (background light)) :background "bisque2") (((class color) (background dark)) :background "bisque4")) "Face for highlighting selection." :group 'minibuffer)  (defface minibuffer-choose-digit '((((class color)) (:foreground "ForestGreen")) (t (:italic t))) "Face for highlighting numeric keys." :group 'minibuffer)  (defface minibuffer-choose-alpha '((((class color)) (:foreground "OrangeRed4")) (t (:weight bold))) "Face for highlighting alpha keys." :group 'minibuffer)  (defvar minibuffer-choose-map (make-sparse-keymap) "Key map used in `minibuffer-choose'.") (set-keymap-parent minibuffer-choose-map minibuffer-local-map)  (define-key minibuffer-choose-map [remap self-insert-command] 'minibuffer-choose-match) (define-key minibuffer-choose-map [left] 'minibuffer-choose-prev) (define-key minibuffer-choose-map [right] 'minibuffer-choose-next) (define-key minibuffer-choose-map [return] 'minibuffer-choose-current) (define-key minibuffer-choose-map "\C-s" 'minibuffer-choose-next) (define-key minibuffer-choose-map "\C-n" 'minibuffer-choose-next) (define-key minibuffer-choose-map "\M-n" 'minibuffer-choose-next) (define-key minibuffer-choose-map (kbd "<tab>") 'minibuffer-choose-next) (define-key minibuffer-choose-map "\C-r" 'minibuffer-choose-prev) (define-key minibuffer-choose-map "\M-p" 'minibuffer-choose-prev) (define-key minibuffer-choose-map "\C-p" 'minibuffer-choose-prev) (define-key minibuffer-choose-map (kbd "<S-tab>") 'minibuffer-choose-prev) (define-key minibuffer-choose-map "\C-a" 'minibuffer-choose-first) (define-key minibuffer-choose-map "\C-e" 'minibuffer-choose-last)  (defun minibuffer-choose-map-key (function) "Apply FUNCTION on each value of the text property 'minibuffer-choose-key and make a list of the results. FUNCTION takes two arguments: the POSITION and VALUE." (let ((inhibit-point-motion-hooks t) (continue t) results) (save-excursion (goto-char (minibuffer-prompt-end)) (while continue (when (get-text-property (point) 'minibuffer-choose-key) (push (funcall function (point) (get-text-property (point) 'minibuffer-choose-key)) results)) (setq continue (next-single-property-change (point) 'minibuffer- choose-key)) (goto-char (or continue (point))))) (nreverse results)))  (defun minibuffer-choose-match () "Set `minibuffer-choose-match' to the field that matches the character you type." (interactive) (declare (special minibuffer-choose-match)) (setq minibuffer-choose-match (car (delete nil (minibuffer-choose-map-key (lambda (pos value) (when (eq last-command-event value) (get-text-property pos 'field))))))) (exit-minibuffer))  (defun minibuffer-choose-current () "Set `minibuffer-choose-match' to the field at point." (interactive) (declare (special minibuffer-choose-match)) (let ((field (get-text-property (point) 'field))) (when field (setq minibuffer-choose-match field))) (exit-minibuffer))  (defun minibuffer-choose-field-search (direction &optional position limit) "Search text property 'field after POSITION and not past LIMIT. If found, the point is moved to the beginning of the field and the new position is returned; else return nil." (let ((search-func (if (memq direction '(nil forward next)) 'next-single-property-change 'previous-single-property-change)) found) (unless position (setq position (point))) (when (setq found (funcall search-func position 'field nil limit)) (goto-char found) (goto-char (field-beginning)))))  (defun minibuffer-choose-key-search () "Search text property 'minibuffer-choose-key in current field and place point on the first occurence." (let (found) (save-excursion (save-restriction (narrow-to-region (field-beginning) (field-end)) (goto-char (point-min)) (setq found (next-single-property-change (point) 'minibuffer-choose-key)))) (when (and found (not (get-text-property (point) 'minibuffer-choose-key)) (goto-char found)))))  (defun minibuffer-choose-first () "Go to the first field." (interactive) (goto-char (minibuffer-prompt-end)) (unless (get-text-property (point) 'field) (minibuffer-choose-field-search 'next (minibuffer-prompt-end))) (minibuffer-choose-key-search))  (defun minibuffer-choose-last () "Go to the last field." (interactive) (minibuffer-choose-field-search 'prev (point-max)) (minibuffer-choose-key-search))  (defun minibuffer-choose-next () "Go to the next field." (interactive) (or (minibuffer-choose-field-search 'next (field-end)) (minibuffer-choose-first)) (minibuffer-choose-key-search))  (defun minibuffer-choose-prev () "Go to the previous field." (interactive) (or (minibuffer-choose-field-search 'prev (field-beginning)) (minibuffer-choose-last)) (minibuffer-choose-key-search))  (defun minibuffer-choose-setup () "This function sets up minibuffer for `minibuffer-choose'." (declare (special minibuffer-choose-choices minibuffer-choose-setup minibuffer-choose-key-type minibuffer-choose-overlay minibuffer-choose-format minibuffer-choose-default separator)) (when (and (boundp 'minibuffer-choose-setup) minibuffer-choose-setup) (setq minibuffer-choose-overlay (make-overlay (point) (point))) (overlay-put minibuffer-choose-overlay 'face 'minibuffer-choose-highlight) (loop for choice in minibuffer-choose-choices for tail = minibuffer-choose-choices then (cdr tail) for index from 1 for display = (cond ((functionp minibuffer-choose-format) (funcall minibuffer-choose-format choice)) ((symbolp choice) (symbol-name choice)) ((stringp choice) choice) (t (error "%s not recognised" choice))) with used-keys with default ; to store the default choice position with beg and end and choice-beginning do (setq beg (point)) (when (equal minibuffer-choose-default choice) (setq default (point))) (when (and (memq minibuffer-choose-key-type '(digit both)) (<= index 10)) (when (= index 10) (setq index 0)) (insert "[" (propertize (number-to-string index) 'minibuffer-choose-key (+ 48 index) 'face 'minibuffer-choose-digit) "]")) (setq choice-beginning (point)) (insert display) (setq end (point)) (when (memq minibuffer-choose-key-type '(alpha both)) (save-excursion (goto-char (1- choice-beginning)) (catch 'exit (while (re-search-forward "[[:alpha:]]" end t) (unless (memq (char-before) used-keys) (push (char-before) used-keys) (add-text-properties (1- (point)) (point) (list 'minibuffer-choose-key (char- before) 'face 'minibuffer-choose- alpha)) (throw 'exit nil)))))) (add-text-properties beg end (list 'field choice 'front-sticky t 'point-entered (lambda (oldpt newpt) (move-overlay minibuffer-choose-overlay (field-beginning) (field- end))))) (when (cdr tail) (insert (or separator " "))) ;; go to the default choice finally (if (null default) (minibuffer-choose-first) (goto-char default) (minibuffer-choose-key-search))) (setq minibuffer-choose-setup nil)))  ;;;; comments for non-trivial let-bound dynamic varialbes: ;;; 1. `minibuffer-choose-setup': indicate whether to perform ;;; minibuffer setup; see also the function with the same name; ;;; 2. `minibuffer-choose-match': value to be returned by `minibuffer-choose'; ;;; 3. `minibuffer-choose-overlay': overlay used in the minibuffer. ;;;; end  ;;;###autoload (defun minibuffer-choose (prompt choices &optional format default key-type  separator) "Present CHOICES in minibuffer with keys to select each choice.  FORMAT is a function to format the display of choices. It will be applied on each element of CHOICES and must return a string to be inserted in the minibuffer.  DEFAULT designates the default choice. If it is a number the nth choice in CHOICES will be used.  KEY-TYPE defaults to digit and takes three values: digit: use digit for keys alpha: use alpha for keys both: use both digit and alpha for keys  SEPARATOR is a string that is inserted between CHOICES." (let ((minibuffer-history nil) ; ignore history from `minibuffer-choose' (minibuffer-choose-setup t) (minibuffer-choose-choices choices) (minibuffer-choose-match nil) (minibuffer-choose-format format) (minibuffer-choose-default (if (numberp default) (nth default choices) default)) (minibuffer-choose-key-type (or key-type 'digit)) (minibuffer-choose-overlay) (minibuffer-setup-hook minibuffer-setup-hook)) (add-hook 'minibuffer-setup-hook 'minibuffer-choose-setup) (read-from-minibuffer prompt nil minibuffer-choose-map) minibuffer-choose-match))  (provide 'minibuffer-choose) ;;; minibuffer-choose.el ends here 
2

1 ответ на вопрос

1
Wes Hardaker

Я не хочу предлагать вам другой выбор, но если вы ищете возможности автоматической вставки, вы можете вместо этого взглянуть на yasnippet, который является мощным и становится дефакто-стандартом для вставок в emacs. У них уже есть куча фрагментов из латекса, над которыми люди работают, но добавить новые довольно просто для всего, что вам нужно.

Похожие вопросы