Debra Cameron - Learning GNU Emacs, 3rd Edition

Здесь есть возможность читать онлайн «Debra Cameron - Learning GNU Emacs, 3rd Edition» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Год выпуска: 2004, ISBN: 2004, Издательство: O'Reilly Media, Жанр: Программы, Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Learning GNU Emacs, 3rd Edition: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Learning GNU Emacs, 3rd Edition»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

GNU Emacs is the most popular and widespread of the Emacs family of editors. It is also the most powerful and flexible. Unlike all other text editors, GNU Emacs is a complete working environment—you can stay within Emacs all day without leaving.
, 3rd Edition tells readers how to get started with the GNU Emacs editor. It is a thorough guide that will also "grow" with you: as you become more proficient, this book will help you learn how to use Emacs more effectively. It takes you from basic Emacs usage (simple text editing) to moderately complicated customization and programming.The third edition of
describes Emacs 21.3 from the ground up, including new user interface features such as an icon-based toolbar and an interactive interface to Emacs customization. A new chapter details how to install and run Emacs on Mac OS X, Windows, and Linux, including tips for using Emacs effectively on those platforms.
, third edition, covers:
• How to edit files with Emacs
• Using the operating system shell through Emacs
• How to use multiple buffers, windows, and frames
• Customizing Emacs interactively and through startup files
• Writing macros to circumvent repetitious tasks
• Emacs as a programming environment for Java, C++, and Perl, among others
• Using Emacs as an integrated development environment (IDE)
• Integrating Emacs with CVS, Subversion and other change control systems for projects with multiple developers
• Writing HTML, XHTML, and XML with Emacs
• The basics of Emacs Lisp
The book is aimed at new Emacs users, whether or not they are programmers. Also useful for readers switching from other Emacs implementations to GNU Emacs.

Learning GNU Emacs, 3rd Edition — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Learning GNU Emacs, 3rd Edition», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Let's look at the source code that makes this all happen! (As always, if you don't want to type the code listed in Example 11-4yourself, you can download it from this book's web site. [79])

Example 11-4. template.el

;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;

;; template.el --- Routines for generating smart skeletal templates for files.

(defvar template-file-name "file-template"

"*The name of the file to look for when a find-file request fails. If a

file with the name specified by this variable exists, offer to use it as

a template for creating the new file. You can also have mode-specific

templates by appending \"-extension\" to this filename, e.g. a Java specific

template would be file-template-java.")

(defvar template-replacements-alist

'(("%filename%" . (lambda ( )

(file-name-nondirectory (buffer-file-name))))

("%creator%" . user-full-name)

("%author%" . user-full-name)

("%date%" . current-time-string)

("%once%" . (lambda ( ) (template-insert-include-once)))

("%package%" . (lambda ( ) (template-insert-java-package)))

("%class%" . (lambda ( ) (template-insert-class-name)))

)

"A list which specifies what substitutions to perform upon loading a

template file. Each list element consists of a string, which is the target

to be replaced if it is found in the template, paired with a function,

which is called to generate the replacement value for the string.")

(defun find-template-file ( )

"Searches the current directory and its parents for a file matching

the name configured for template files. The name of the first such

readable file found is returned, allowing for hierarchical template

configuration. A template file with the same extension as the file

being loaded (using a \"-\" instead of a \".\" as the template file's

delimiter, to avoid confusing other software) will take precedence

over an extension-free, generic template."

(let ((path (file-name-directory (buffer-file-name)))

(ext (file-name-extension (buffer-file-name)))

attempt result)

(while (and (not result) (> (length path) 0))

(setq attempt (concat path template-file-name "-" ext))

(if (file-readable-p attempt)

(setq result attempt)

(setq attempt (concat path template-file-name))

(if (file-readable-p attempt)

(setq result attempt)

(setq path (if (string-equal path "/")

""

(file-name-directory (substring path 0 -1)))))))

result))

(defun template-file-not-found-hook ( )

"Called when a find-file command has not been able to find the specified

file in the current directory. Sees if it makes sense to offer to start it

based on a template."

(condition-case nil

(if (and (find-template-file)

(y-or-n-p "Start with template file? "))

(progn (buffer-disable-undo)

(insert-file (find-template-file))

(goto-char (point-min))

;; Magically do the variable substitutions

(let ((the-list template-replacements-alist))

(while the-list

(goto-char (point-min))

(replace-string (car (car the-list))

(funcall (cdr (car the-list)))

nil)

(setq the-list (cdr the-list))))

(goto-char (point-min))

(buffer-enable-undo)

(set-buffer-modified-p nil)))

;; This is part of the condition-case; it catches the situation where

;; the user has hit C-g to abort the find-file (since they realized

;; that they didn't mean it) and deletes the buffer that has already

;; been created to go with that file, since it will otherwise become

;; mysterious clutter they may not even know about.

('quit (kill-buffer (current-buffer))

(signal 'quit "Quit"))))

; Install the above routine

(or (memq 'template-file-not-found-hook find-file-not-found-hooks)

(setq find-file-not-found-hooks

(append find-file-not-found-hooks '(template-file-not-found-hook)))

)

(defun template-insert-include-once ( )

"Returns preprocessor directives such that the file will be included

only once during a compilation process which includes it an

arbitrary number of times."

(let ((name (file-name-nondirectory (buffer-file-name)))

basename)

(if (string-match ".h$" name)

(progn

(setq basename (upcase (substring name 0 -2)))

(concat "#ifndef _H_" basename "\n#define _H_" basename

"\n\n\n#endif /* not defined _H_" basename " */\n"))

"" ; the "else" clause, returns an empty string.

)))

(defun template-insert-java-package ( )

"Inserts an appropriate Java package directive based on the path to

the current file name (assuming that it is in the com, org or net

subtree). If no recognizable package path is found, inserts nothing."

(let ((name (file-name-directory (buffer-file-name)))

result)

(if (string-match "/\\(com\\|org\\|net\\)/.*/$" name)

(progn

(setq result (substring name (+ (match-beginning 0) 1)

(- (match-end 0) 1)))

(while (string-match "/" result)

(setq result (concat (substring result 0 (match-beginning 0))

"."

(substring result (match-end 0)))))

(concat "package " result ";"))

"")))

(defun template-insert-class-name ( )

"Inserts the name of the java class being defined in the current file,

based on the file name. If not a Java source file, inserts nothing."

(let ((name (file-name-nondirectory (buffer-file-name))))

(if (string-match "\\(.*\\)\\.java" name)

(substring name (match-beginning 1) (match-end 1))

"")))

(provide 'template)

You'll notice that this code makes heavy use of the regular expression facilities, which is no surprise. The first section sets up some variables that configure the operation of the template system. template-file-namedetermines the file name (or prefix) that is used to search for templates; the default value of file-templateis probably fine. template-replacements-alistsets up the standard placeholders, and the mechanism by which they get replaced by appropriate values. Adding entries to this list is one way to extend the system. Each entry consists of the placeholder to be replaced, followed by the Lisp function to be executed to produce its replacement. The way this function can be stored in a list and executed when appropriate later is one of the great things about Lisp and is discussed in more depth in the calculator mode example in the next section. The placeholders supported are:

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Learning GNU Emacs, 3rd Edition»

Представляем Вашему вниманию похожие книги на «Learning GNU Emacs, 3rd Edition» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Learning GNU Emacs, 3rd Edition»

Обсуждение, отзывы о книге «Learning GNU Emacs, 3rd Edition» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x