Como inserir * .tex-templates no buffer do Emacs usando o minibuffer-choose.el?


2

Semanas atrás eu encontrei esta resposta para https://tex.stackexchange.com/questions/2110/most-significant-reasons-that-led-%20us-to-latex/2144#2144 em tex.stackexchange.com.

"Leo2007" descreve como inserir * .tex-templates em um buffer do Emacs. Eu não consegui descobrir, como fazer isso funcionar e decidi pergunte na lista de discussão autex , mas não obteve resposta por três semanas. Então talvez você possa me ajudar:

"Leo2007" apresentou o arquivo minibuffer-choose.el, que deve permitir inserir um modelo em um documento rapidamente. Siga o link Nr. 1 acima e você verá um imagem bastante convincente.

Infelizmente eu não entendo como usá-lo. Eu peguei o arquivo minibuffer-choose.el daqui: http://paste.lisp.org/display/113728 (Eu adicionei abaixo).

Eu fiz uma compilação de byte, coloquei onde o emacs pode encontrá-lo e adicionei 3 linhas ao meu arquivo .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

Respostas:


1

Eu odeio oferecer outra opção, mas se você está procurando por recursos de inserção automática, você pode yasnippet em vez disso, é um poderoso mau e se torna o padrão-de-fato para as inserções do emacs. Eles já têm um monte de fragmentos de látex que as pessoas têm trabalhado, mas adicionando novas é bastante fácil para qualquer coisa especial que você precisa para si mesmo.

Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.