Jump to content

Help:Text editor support

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by CYD (talk | contribs) at 07:14, 24 April 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Many text editors provide special features for editing source code, which are applicable for editing wiki-markup. The most common and useful feature is syntax highlighting, which alters the appearance of syntactic elements to make them stand out from the rest of the text. Below are files for adapting Emacs and Vim to wikipedia markup.

Tips for all editors

You can configure an external editor for editing wikipedia articles without copying and pasting them from the web textarea in Mozilla and Mozilla Firefox. Just download the extension "mozex" at http://mozex.mozdev.org/. This allows you to edit any text area in your favorite editor by right-clicking. Another similar tool is "electrix" at http://electrix.mozdev.org/

Emacs

Wikipedia-mode

Emacs support for editing wikipedia articles is provided by a major-mode called wikipedia-mode.

Installation

Save wikipedia-mode.el to a convenient directory, preferably one in your Emacs load-path. To see which directories are in your load-path, type C-h v load-path

Open your Emacs initialization file. This is usually a file called .emacs in your home directory. Append the following lines:

(autoload 'wikipedia-mode "wikipedia-mode.el"
  "Major mode for editing documents in Wikipedia markup." t)

If you did not save wikipedia-mode.el in a `load-path' directory, replace "wikipedia-mode.el" with the full pathname. On Windows, use forward slashes ("/") rather than back slashes ("\") to indicate the directory. For example,

(autoload 'wikipedia-mode "C:/Documents and Settings/USERNAME/.emacs.d/Wikipedia-mode.el"
  "Major mode for editing documents in Wikipedia markup." t)

To associate filenames ending in ".wiki" with wikipedia-mode, add the following to your Emacs initialization file:

 (add-to-list 'auto-mode-alist '("\\.wiki\\'" . wikipedia-mode))

Usage

To enter wikipedia-mode, type M-x wikipedia-mode. To see a description of wikipedia-mode, type C-h m (describe-mode) while in wikipedia-mode.

Outline modes

It is convenient to use wikipedia-mode in conjunction with an outline mode of Emacs, which allows sections of an article to be hidden from view. This allows you, for example, to view only the headlines of an article, hiding the text body, or view only the body of the section you are editing.

There are two ways of doing this: outline-minor-mode or an altered version of org-mode. outline-minor-mode has the advantage that it is already built into Emacs, and can be used together with wikipedia-mode for syntax highlighting. Org-mode is a little easier to use, but it cannot be used at the same time as wikipedia-mode.

outline-minor-mode

To activate outline-minor-mode, type M-x outline-minor-mode after you have entered wikipedia-mode. See the documentation for outline-mode (C-h f outline-mode) for information on how to use the outline commands.

org-mode

org-mode is very easy to use, because you only need the tab key: If the cursor is on a headline, just press tab and you will cycle through the view modes. If you want to cycle through the modes for the complete file, make sure the file begins with an empty line, position your cursor on it and press tab. Detailed explanations can be found in the file org.el below.

To use org-mode, download and install org.el (instructions are in the file).

Vim

To make Vim support wikipedia markup, save wikipedia.vim to your "syntax" directory. By default, this directory is "~/.vim/syntax" on a Unix system, and "C:\Program Files\Vim\vimfiles\syntax" on a Windows system.

To autodetect files ending in ".wiki", add the following lines to ".vim/filetype.vim" or "vimfiles\filetype.vim" (or create the file if it doesn't exist):

augroup filetypedetect
au BufNewFile,BufRead *.wiki	setf wikipedia
augroup END

Alternatively, the command "set syn=wikipedia" will temporarily set the syntax for the current file.

Wikipedia articles often only have line-breaks at the end of each paragraph, a situation Vim is not designed for. The following lines added to your ".vimrc" or "_vimrc" file will make it much easier to edit such files:

set tw=0
set lbr
map <Up> gk
map <Down> gj
imap <Up> <C-O>gk
imap <Down> <C-O>gj

Please feel free to edit wikipedia.vim and upload an improved copy.

Example as shown by Vim

The following passage, which is actually written in HTML, simulates what Vim's syntax highlighting looks like.

Syntax highlighting sample with the "murphy" colour scheme

[[link]] [http://arin.net/whois External link] [editorial remark]
* Bullet
; Definition
# Numbered list
:: Multiple indenting
This: # is not a numbered list

<strong>HTML formatting <i>bold-italic</i> bold</strong>

<a href="Hello">Absence of HTML formatting</a>

 preformatted
''italic'' '''bold''' '''''bold-italic'''''

'''[[bold links are not very bold]]'''
<math>\left(Not-A\right)</math>
<font color=red>
==H2==
Example with text behore header code ===H3===
-----
</font>

This example shows the use of colors and that bold and italics are applied (but not in the case of bold links), but the font difference between normal and preformatted is not shown. It also shows (by color) that a numbering or header code with text in front is treated as a regular text. Furthermore colors specified for the article are not applied here because they would interfere with the color scheme.