Skip to Content
Writing GNU Emacs Extensions
book

Writing GNU Emacs Extensions

by Bob Glickstein
April 1997
Intermediate to advanced
240 pages
5h 56m
English
O'Reilly Media, Inc.
Content preview from Writing GNU Emacs Extensions

Chapter 4. Searching and Modifying Buffers

There will be lots of times when you want to search through a buffer for a string, perhaps replacing it with something else. In this chapter we'll show a lot of powerful ways to do this. We'll cover the functions that perform searches and also show you how to form regular expressions, which add great flexibility to the kinds of searches you can do.

Inserting the Current Time

It is sometimes useful to insert the current date or time into a file as you edit it. For instance, right now, as I'm writing this, it's 10:30pm on Friday, 18 August, 1996. A few days ago, I was editing a file of Emacs Lisp code and I changed a comment that read

;; Each element of ENTRIES has the form
;; (NAME (VALUE-HIGH . VALUE-LOW))

to

;; Each element of ENTRIES has the form
;; (NAME (VALUE-HIGH . VALUE-LOW))
;; [14 Aug 96] I changed this so NAME can now be a symbol,
;; a string, or a list of the form (NAME . PREFIX) [bg]

I placed a timestamp in the comment because it could be useful when editing that code in the future to look back and see when this change was made.

A command that merely inserts the current time is simple, once you know that the function current-time-string yields today's date and time as a string.[18]

(defun insert-current-time ()
  "Insert the current time"
  (interactive "*")
  (insert (current-time-string)))

The section More Asterisk Magic later in this chapter explains the meaning of (interactive ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

GNU Emacs Pocket Reference

GNU Emacs Pocket Reference

Debra Cameron
Learning GNU Emacs, Second Edition

Learning GNU Emacs, Second Edition

Debra Cameron, Bill Rosenblatt, Eric S. Raymond

Publisher Resources

ISBN: 9781449395056Errata Page