From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "metaperl.com" Newsgroups: gmane.emacs.help Subject: code critique requested Date: Fri, 30 Nov 2007 08:10:44 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1196440846 11419 80.91.229.12 (30 Nov 2007 16:40:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Nov 2007 16:40:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 30 17:40:54 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Iy8v2-0000B5-Fh for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Nov 2007 17:40:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Iy8um-0005MU-Mi for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Nov 2007 11:40:32 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!g30g2000hsb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 427 Original-NNTP-Posting-Host: 159.53.78.143 Original-X-Trace: posting.google.com 1196439045 1666 127.0.0.1 (30 Nov 2007 16:10:45 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 30 Nov 2007 16:10:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g30g2000hsb.googlegroups.com; posting-host=159.53.78.143; posting-account=GDJYuQoAAACvR3VU3OOyv8hdViWomHUu User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; TheWorld),gzip(gfe),gzip(gfe) Content-Disposition: inline Original-Xref: shelby.stanford.edu gnu.emacs.help:154301 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49729 Archived-At: Hi, any feedback on improving this is appreciated. I have been getting some reports with warnings on byte-compilation. I'm mainly interested in GNU Emacs correctness, but if I can support both major emacsen without too much hassle, then I will do it. ;;; asciidoc.el --- asciidoc text file development support ;; Copyright (C) 2007 Terrence Brannon ;; Author: Terrence Brannon ;; Created: 21 Sept 2007 ;; Version: 0.1 ;; Keywords: text-formatting ;; This file is not (yet) part of GNU Emacs. ;; However, it is distributed under the same license. ;; GNU Emacs 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 2, or (at your option) ;; any later version. ;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Description: ;; Suggested (but entirely optional) add-ons: ;; doc-mode: font-locking for asciidoc buffers ;; http://xpt.sourceforge.net/tools/doc-mode/ ;; - connect asciidoc.el to doc-mode as follows: ;; (autoload 'doc-mode "doc-mode" nil t) ;; (add-to-list 'auto-mode-alist '("\\.adoc$" . doc-mode)) ;; (add-hook 'doc-mode-hook ;; '(lambda () ;; (turn-on-auto-fill) ;; (require 'asciidoc))) ;; Author extends thanks to: ;; Steve Youngs (JackaLX on irc://irc.freenode.net/xemacs) ;; bpalmer, twb ;; Alexander Kinzer - byte-compile bug reports ;; Version control: ;; This software is under Mercurial version control and maybe retrieved via: ;; hg clone http://hg.metaperl.com/asciidoc-el ;; Code: (setq debug-on-error t) (require 'easymenu) (require 'cl) (require 'apropos) (require 'compile) (defvar *asciidoc-indent-level* 2 "Number of spaces to indent per level") (defvar *delimiter-length* 70 "How many characters to use when building a delimited block string. 4 min") (defun asciidoc-header (title author revision) "Insert asciidoc header consisting of TITLE and optional AUTHOR and REVISION" (interactive "sHeader title: \nsHeader author (return if none): \nsHeader revision (return if none):") (insert (concat title "\n" (make-string (length title) ?=) "\n" author "\n" revision "\n" "\n" ))) (defun asciidoc-get-started () (interactive) (let ((date (format-time-string "%D" (current-time)))) (asciidoc-header "Document Title" "Terrence Brannon " date))) (defun asciidoc-emphasized (text) "Insert text with asciidoc emphasis formatting" (interactive "sText to be emphasized: ") (insert (concat "_" text "_"))) (defun asciidoc-strong (text) "Insert text with asciidoc strong formatting" (interactive "sText to be strong-formatted: ") (insert (concat "*" text "*"))) (defun asciidoc-monospace (text) "Insert text with asciidoc monospace formatting" (interactive "sText to be monospace formatted: ") (insert (concat "`" text "`"))) (defun asciidoc-quoted (text) "Insert text with asciidoc quoted-text formatting" (interactive "sText to be enclosed in quotation marks: ") (insert (concat "``" text "''"))) (defun asciidoc-unquoted (text) "Insert text with asciidoc unquoted text formatting" (interactive "sText to be non-quoted: ") (insert (concat "#" text "#"))) (defun asciidoc-passthru-triple-plus (text) "Insert text with asciidoc triple plus passthrough formatting" (interactive "sText to be formatted for no change: ") (insert (concat "+++" text "+++"))) (defun asciidoc-passthru-double-dollar (text) "Insert text with asciidoc double-dollar formatting" (interactive "sText to be formatted for no change except escaping special characters: ") (insert (concat "$$" text "$$"))) (defun asciidoc-superscript (text) "Insert text with asciidoc superscript formatting" (interactive "sText to be formatted for superscripting: ") (insert (concat "^" text "^"))) (defun asciidoc-subscript (text) "Insert text with asciidoc subscript formatting" (interactive "sText to be formatted for subscripting: ") (insert (concat "~" text "~"))) (defun asciidoc-line-break () "Insert asciidoc forced line break" (interactive) (insert (concat " +\n"))) (defun asciidoc-horizontal-rule () "Insert asciidoc
tag for HTML only" (interactive) (insert (concat "'''\n"))) (defun asciidoc-copyright () "Insert asciidoc copyright replacement" (interactive) (insert "(C) ")) (defun asciidoc-trademark () "Insert asciidoc copyright replacement" (interactive) (insert "(TM) ")) (defun asciidoc-registered-trademark () "Insert asciidoc registered copyright replacement" (interactive) (insert "(R) ")) (defun asciidoc-section-title (section-level title) "Insert asciidoc one-line title syntax" (interactive "NNumber of equals signs (2-4): \nsSection title: ") ; " " equals-signs (let ((equals-signs (make-string (1+ section-level) ?=))) (insert (concat "\n" equals-signs " " title "\n\n")))) (defun asciidoc-block-title (text) "Insert text with asciidoc block title formatting" (interactive "sText to be formatted as block title: ") (insert (concat "." text "\n"))) (defun asciidoc-block-id-element (text) "Insert text with asciidoc BlockId Element formatting" (interactive "sText to be formatted as block-id: ") (insert (concat "[[" text "]]" "\n"))) (defun asciidoc-block-reference (block-id descriptive-text) "Insert asciidoc reference to a block consisting of BLOCK-ID and DESCRIPTIVE-TEXT" (interactive "sBlockId: \nsDescriptive text: ") (insert (concat "<<" block-id "," descriptive-text ">>" ))) (defun asciidoc-verse-paragraph (text) "Insert verse paragraph formatting" (interactive) (insert (concat "[verse]" "\n"))) (defun asciidoc-literal-paragraph (text) "Insert literal paragraph formatting" (interactive) (insert (concat " " "\n"))) (defun asciidoc-admonition-paragraph (text) "Insert admonition paragraph formatting" (interactive) (insert (concat "[NOTE]" "\n"))) (defun asciidoc-delimited-block (delimiter text) "" (let ((str (make-string *delimiter-length* delimiter))) (insert (concat str "\n" text "\n" str "\n\n")))) (defun asciidoc-comment-block (text) "create an asciidoc CommentBlock" (interactive "sText for comment block? ") (asciidoc-delimited-block ?/ text)) (defun asciidoc-passthru-block (text) "create an asciidoc PassthroughBlock" (interactive "sText for passthru block? ") (asciidoc-delimited-block ?+ text)) (defun asciidoc-listing-block (text) "create an asciidoc ListingBlock" (interactive "sText for listing block? ") (asciidoc-delimited-block ?- text)) (defun asciidoc-literal-block (text) "create an asciidoc LiteralBlock" (interactive "sText for literal block? ") (asciidoc-delimited-block ?. text)) (defun asciidoc-sidebar-block (text) "create an asciidoc SidebarBlock" (interactive "sText for sidebar block? ") (asciidoc-delimited-block ?* text)) (defun asciidoc-example-block (text) "create an asciidoc ExampleBlock, using TEXT and optionally modifying the default EXAMPLE-LABEL and EXAMPLE-DESCRIPTION" (interactive "sText for example block? ") (let ((example-label (read-string "Example label? (it needs a space at the end) " "Example: ")) (example-description (read-string "Example description? " "An example"))) (if (not (string= "" example-label)) (insert "[caption=" "\"" example-label "\"" "]" "\n")) (if (not (string= "" example-description)) (insert "." example-description "\n")) (asciidoc-delimited-block ?= text))) (defun asciidoc-quotation-block (text author source) "create an asciidoc QuoteBlock" (interactive "sText of quotation? \nsAuthor of quotation? \nsWhere did this quotation come from? ") (insert (concat "[" "attribution=" "\"" author "\"" "," "citetitle=" "\"" source "\"" "]" "\n")) (asciidoc-delimited-block ?_ text)) (defun asciidoc-compile () (interactive) (setq compile-command (concat "asciidoc -a numbered -a toc -a toclevels=4" " " (file-name-nondirectory (buffer-file-name)) )) (call-interactively 'compile)) (defvar *asciidoc-bullet* '("-" "*") "strings representing each of the two bullet levels offered by Asciidoc") (defun asciidoc-bullet-item (bullet-level text) "At BULLET_LEVEL, insert TEXT" (interactive "NBullet level (1 or 2): \nsText for bullet: ") (let* ((level (if (= bullet-level 2) 1 0)) (bullet (nth level *asciidoc-bullet*)) (tab-space (make-string (* level 4) ?\s))) (insert (concat tab-space bullet " " text "\n")))) (defun asciidoc-numbered-list-item (item-level text) "At ITEM-LEVEL, insert TEXT" (interactive "NItem level (1 or 2): \nsText for bullet: ") (let* ((level (if (= item-level 2) 2 1)) (bullet (make-string level ?.)) (tab-space (make-string (* (- level 1) 4) ?\s))) (insert (concat tab-space bullet " " text "\n")))) (defun asciidoc-labelled-list-item (text) "Insert TEXT" (interactive "sLabel for list item: ") (insert (concat text "::" "\n "))) (defun asciidoc-bibliography-item (ref-label ref-text) "Insert bibliography item consisting of REF-LABEL and REF-TEXT" (interactive "sLabel for bib item: \nsText of bibitem: ") (insert (concat "+" " " "[[[" ref-label "]]]" " " ref-text "\n"))) (defun asciidoc-href (url link-text) "Insert hyperlink consisting of URL and LINK-TEXT" (interactive "sURL: \nsText describing URL: ") (insert (concat url "[" link-text "]" "\n" ))) (defun asciidoc-relative-href (url link-text) "Insert hyperlink consisting of URL and LINK-TEXT" (interactive "sRelative path to file (anchors allowed): \nsText describing link: ") (insert (concat "link:" url "[" link-text "]" "\n" ))) (defun asciidoc-image-href (url link-text) "Insert hyperlink consisting of URL and LINK-TEXT" (interactive "sURL to image file: \nsText describing image (only displayed when image unavailable): ") (insert (concat "image:" url "[" "\"" link-text "\"" "]" "\n" ))) (setq asciidoc-global-menuspec (list "Doc" (list "Links and refs" (vector "Href" 'asciidoc-href) (vector "Image" 'asciidoc-image-href) (vector "Relative url" 'asciidoc-relative-href) (vector "Internal document references" 'asciidoc-block- reference) ) (list "Reference items" (vector "Bibliography listing" 'asciidoc-bibliography-item) (vector "BlockId element" 'asciidoc-block-id-element)) (list "Bullets and lists" (vector "Bulleted list" 'asciidoc-bullet-item) (vector "Numbered list" 'asciidoc-numbered-list-item) (vector "Labelled list" 'asciidoc-labelled-list-item) ) (list "Text formatting" (vector "Emphasis" 'asciidoc-emphasized) (vector "Strong (bold)" 'asciidoc-strong) (vector "Monospaced" 'asciidoc-monospace) (vector "Quotation marks around text" 'asciidoc-quoted) (vector "Superscript" 'asciidoc-superscript) (vector "Subscript" 'asciidoc-subscript) ) (list "Special symbols" (vector "Copyright" 'asciidoc-copyright) (vector "Trademark" 'asciidoc-trademark) (vector "Registered trademark" 'asciidoc-registered-trademark) ) (list "Blocks" (vector "Example block" 'asciidoc-example-block) (vector "Listing block" 'asciidoc-listing-block) (vector "Quotation block" 'asciidoc-quotation-block) (vector "Literal block" 'asciidoc-literal-block) (vector "Sidebar block" 'asciidoc-sidebar-block) (vector "Comment block" 'asciidoc-comment-block) (vector "Pass-through block" 'asciidoc-passthru-triple-plus) ) (list "Run Asciidoc" (vector "Compile" 'asciidoc-compile) (vector "Recompile" 'recompile) ) (vector "Start document" 'asciidoc-get-started) )) (easy-menu-define asciidoc-global-menu global-map "" asciidoc-global-menuspec) (provide 'asciidoc) ;;; asciidoc.el ends here