🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.emacs
Article #9742

auto-complete-auctex (code complet)

#9742
From: Guy
Date: Sun, 02 Oct 2011 17:14
315 lines
9758 bytes
Avec le code complet c'est mieux !!!


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




;; ac-latex-symbols with LaTeX-math-mode
(defvar ac-symbols-auctex
   (mapcar 'cadr LaTeX-math-default))

(defvar ac-symbols-list
   (mapcar 'cdr LaTeX-math-default))


;; candidate
(defun ac-symbols-candidate ()
   "List of math symbol"
   (all-completions ac-prefix ac-symbols-auctex))




;; action


(defun ac-symbols-action ()
   (re-search-backward candidate)
   (delete-region (match-beginning 0) (match-end 0))
   (ac-symbols-insert candidate))


;; some documentation
(defun ac-symbols-doc (c)
   "Some help for the candidate"
   (let* ((cl (assoc c ac-symbols-list))
	 (decode (if (nth 2 cl) (char-to-string (decode-char 'ucs (nth 2 cl))) ""))
	 (st (nth 1 cl))
	 (hs (if (listp st)(mapconcat 'identity st " ")st))
	 (help (concat hs " == " decode))
	 )
     help
     )
   ) ;;  ac-symbols-doc


(defun LaTeX-math-mode-on ()
   (LaTeX-math-mode 1))


(ac-define-source LaTeX-symbols
   '((init . LaTeX-math-mode-on)
     (candidates . ac-symbols-candidate)
     (document . ac-symbols-doc)
     (action . ac-symbols-action)
     (requires . 1)
     (candidate-face . ac-latex-candidate-face)
     (selection-face . ac-latex-selection-face)
     (symbol . "s")
     )
   ) ;; LaTeX-symbols

;; ac-sources-LaTeX-symbols

;;;  LaTeX-environmants source and action

(defun ac-source-latex-environments ()
     (let ((envlist (mapcar 'car LaTeX-environment-list))
    	)

     (all-completions ac-prefix envlist))
   ) ;; ac-latex-source-environments

;; action pour les environments
(defun action-auctex-environment ()
   (re-search-backward candidate)
   (delete-region (match-beginning 0) (match-end 0))
   (LaTeX-environment-menu candidate)
   ) ;; action-auctex-environment



(ac-define-source LaTeX-environments
   '((init . LaTeX-environment-list)
     (candidates . ac-source-latex-environments)
     (document .  TeXdoc)
     (cache)
     (action .  action-auctex-environment)
     (requires . 2)
     (selection-face . ac-latex-selection-face)
     (candidate-face . ac-latex-candidate-face)
     (symbol . "e")))

;;; end LaTeX environments source and action






;; some help if you work with TeXlive
;; you can change it if too long. F1 give help immediateley
;; this work with TeXlive
(setq ac-quick-help-delay 4.5)

;; work with TeXlive
(defun TeXdoc (item)
   (interactive)
   (TeX-doc item))
  ;; end of TeXdoc





;; setup  you call ac-latex-setup with LaTeX-mode-hook
;;;###autoload
(defun ac-latex-setup ()
   (interactive)
   (TeX-symbol-list)
   (LaTeX-environment-list)
   (setq ac-sources (append
		      '(ac-source-LaTeX-symbols
			ac-source-LaTeX-macros ac-source-LaTeX-environments)
		      ac-sources))
   )

(provide 'auto-complete-auctex)
;;;  end of auto-complete-package
Technical Details
Message-ID: <4e889bda$0$30624$426a74cc@news.free.fr>
Path: arc1-ca.pugleaf.net!lh7ni9943pbb.0!nntp.google.com!news1.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!feeder1-1.proxad.net!proxad.net!feeder1-2.proxad.net!212.27.60.64.MISMATCH!cleanfeed3-b.proxad.net!nnrp15-2.free.fr!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 102b9a,c2fc158b86d5c2e1,start
X-Google-NewGroupId: yes
X-Google-Thread: f5a1a,c2fc158b86d5c2e1,start
X-Google-NewGroupId: yes
X-Google-Thread: 10ee61,c2fc158b86d5c2e1,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid853c49a5d,gid4163a3d9b8,giddbc56467f1,domainid0,public,usenet
X-Google-Language: FRENCH,UTF8
Received: by 10.68.11.199 with SMTP id s7mr57353643pbb.5.1317575643214;
        Sun, 02 Oct 2011 10:14:03 -0700 (PDT)
Path: arc1-ca.pugleaf.net!lh7ni9943pbb.0!nntp.google.com!news1.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!feeder1-1.proxad.net!proxad.net!feeder1-2.proxad.net!212.27.60.64.MISMATCH!cleanfeed3-b.proxad.net!nnrp15-2.free.fr!not-for-mail
Date: Sun, 02 Oct 2011 19:14:02 +0200
From: Guy <Paul.Lennon@free.fr>
Reply-To: JohnPaul@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 (code complet)
Lines: 322
Message-ID: <4e889bda$0$30624$426a74cc@news.free.fr>
NNTP-Posting-Date: 02 Oct 2011 19:14:02 MEST
NNTP-Posting-Host: 82.66.47.80
X-Trace: 1317575642 news-3.free.fr 30624 82.66.47.80:36390
X-Complaints-To: abuse@proxad.net
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit