🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.emacs
Article #9741

auto-complete-auctex

#9741
From: Guy
Date: Fri, 30 Sep 2011 08:51
186 lines
6590 bytes
voici un package, nommé dorénavant,  auto-complete-auctex, (en hommage à 
AucTeX et à auto-complete)  qui permet d'utiliser la completion  (via 
des menus) pour l'écrire de fichiers LaTeX avec auxtex.

sont traités:

les environements, les macros et les symboles

par exemple  si vous tapez   "enu" dans le tampon vous voyez apparaitre 
un menu avec tous les environments, macros et symboles commancant par 
ces trois lettres.

vous pointez celui que vous voulez il est inscrit dans le tempon avec le 
slash si c'est une macro et entre les $ si c'est un symbole mathématique.

une aide apparait (le temps dépend du choix vir les paramètres 
d'auto-complete))

pour faire fonctionner ce soft selon vos désiratas il faut choisir les 
paramètres d'auto-complete  qui vous conviennent.

Happy TeXing,
Guy yétérian




;;; auto-complete-auctex  --- auto-complete for LaTeX auctex

;; Copyright (C) 2010 Guy Yeterian gyecmonet <@> free <dot> fr

;; Author: Guy Yeterian
;; Maintainer: the author
;; Created: 07 Aug 2010
;; Version: 1.0
;; version  1.8 Jun 2011
;; version  1.9 Aug 2011
;; Keywords: auctex auto-complete



;; 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 1, 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.

;; A copy of the GNU General Public License can be obtained from this
;; program's author (send electronic mail to
;; root@localhost.localdomain) or from the Free Software Foundation,
;; Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;; LCD Archive Entry:
;; ac-latex|rockymyroot|root@localhost.localdomain
;; |auto-complete for LaTeX auctex
;; |$Date$|$Revision$|~/packages/ac-latex.el

;;; Installation
;;  This is a very useful package to write LaTeX documents with aucTeX 
and auto-complete
;;  To use this package you must install aucTeX and auto-complete packages.
;;  Just add to the .emacs file:
;;     (autoload 'ac-latex-setup "auto-complete-latex" "ac and aucTeX" t)
;;     (add-hook 'LaTeX-mode-hook (lambda() (ac-latex-setup)))
;;  when you type 'enu' you must see all (even yours) laTeX-environments 
and TeX-macros that
;;  begins with this words.
;;  Because of the use of auto-complete package you must customize this 
for yours needs.
;;  In particular  see ac-delay,  ac-auto-show-menu and ac-quick-help-delay.


;;; Commentary:
;;  Free softwards are great and make me happy.
;;  Many thanks to Richard Stallman for free softward concept and for emacs.
;;  Many thanks for the aucTeX group.
;;  Many thanks for auto-complete author Tomohiro Matsuyama.

;;; Change log:
;; $Log$

;;; Code:
(provide 'auto-complete-auctex)

(require 'tex)
(require 'latex)


(eval-when-compile
    (require 'auto-complete))
    ;;(require 'popup-pos-tip))



;; some custome and globals functions

(defface ac-latex-candidate-face
    '((t (:background "LemonChiffon1" :foreground "black")))
    "Face for LaTeX candidate."
    :group 'LaTeX)

(defface ac-latex-selection-face
    '((t (:background "goldenrod" :foreground "black")))
    "Face for the LaTeX selected candidate."
    :group 'LaTeX)


;; add LaTeX-mode to ac-modes
(setq ac-modes (append '(LaTeX-mode latex-mode) ac-modes))



(defvar candidate nil
    "Just for the Elisp compiler not complain")



(defun my-LaTeX-math-insert (s dollar)
    "Insert s with dollar if necessary"
    (when dollar (insert "$"))
    (funcall LaTeX-math-insert-function s)
    (if dollar
        (progn
	(let ((d (point)))
	  (re-search-forward "[{.*}]*\}" (+ (point) 10) t)
	  (insert "$")
	  (goto-char d))))
    ) ;; end my-LaTeX-math-insert



;; Function to insert TeX-macro
(defun ac-symbols-insert (s)
    "Insert math symbol s with dollar if necessary"
    (let ((dollar (if (texmathp)
		    nil
		  t)))
      (my-LaTeX-math-insert s dollar)
      )) ;; ac-symbols-insert




;;; TeX-macros source and action

(defun ac-source-latex-macros ()
     (let ((comlist (if TeX-symbol-list
		     (mapcar (lambda (x)
    		       (if (listp x)
    			   (car x)
    			 x))
    		       (mapcar 'car TeX-symbol-list)))))
      (all-completions ac-prefix comlist))) ;; ac-latex-source-commandes

;; end globas functions





;;; action on macros
(defun action-auctex-macro ()
    (re-search-backward candidate)
    (delete-region (match-beginning 0) (match-end 0))
    (LaTeX-math-insert candidate nil)
    ) ;; action-auctex-commande



(ac-define-source  LaTeX-macros
    '((init . TeX-symbol-list)
      (candidates . ac-source-latex-macros)
      (document . TeXdoc)
      (cache)
      ;(depends . '(LaTeX-mode  auto-complete-mode))
      (action . action-auctex-macro)
      (requires . 2)
      (candidate-face . ac-latex-candidate-face)
      (selection-face . ac-latex-selection-face)
      (symbol . "m")));; LaTeX-macros

;; end TeX macros
Technical Details
Message-ID: <4e858320$0$25233$426a74cc@news.free.fr>
Path: arc1-ca.pugleaf.net!lh7ni8163pbb.0!nntp.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!proxad.net!feeder1-2.proxad.net!cleanfeed1-a.proxad.net!nnrp5-2.free.fr!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 102b9a,1258e34e07ea455c,start
X-Google-NewGroupId: yes
X-Google-Thread: f5a1a,1258e34e07ea455c,start
X-Google-NewGroupId: yes
X-Google-Thread: 10ee61,1258e34e07ea455c,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid853c49a5d,gid4163a3d9b8,giddbc56467f1,domainid0,public,usenet
X-Google-Language: FRENCH,UTF8
Received: by 10.68.27.230 with SMTP id w6mr15787932pbg.3.1317372705054;
        Fri, 30 Sep 2011 01:51:45 -0700 (PDT)
Path: arc1-ca.pugleaf.net!lh7ni8163pbb.0!nntp.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!proxad.net!feeder1-2.proxad.net!cleanfeed1-a.proxad.net!nnrp5-2.free.fr!not-for-mail
Date: Fri, 30 Sep 2011 10:51:44 +0200
From: Guy <Paul.Lennon@free.fr>
Organization: Education
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2
MIME-Version: 1.0
Newsgroups: comp.emacs,fr.comp.applications.emacs,fr.comp.text.tex
Followup-To: johnpaul@free.fr
Subject: auto-complete-auctex
Lines: 192
Message-ID: <4e858320$0$25233$426a74cc@news.free.fr>
NNTP-Posting-Date: 30 Sep 2011 10:51:44 MEST
NNTP-Posting-Host: 82.66.47.80
X-Trace: 1317372704 news-1.free.fr 25233 82.66.47.80:53684
X-Complaints-To: abuse@proxad.net
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit