From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anselm Helbig Newsgroups: gmane.emacs.help Subject: Re: Advice on writing predicates Date: Fri, 26 Jun 2009 01:23:56 +0200 Organization: Freie Universitaet Berlin Message-ID: <87bpobgann.wl%anselm.helbig+news2009@googlemail.com> References: NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1245973248 3875 80.91.229.12 (25 Jun 2009 23:40:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Jun 2009 23:40:48 +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 Jun 26 01:40:41 2009 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 1MJyYZ-0002ft-SF for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Jun 2009 01:40:40 +0200 Original-Received: from localhost ([127.0.0.1]:36946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MJyYZ-0001N7-6y for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Jun 2009 19:40:39 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Original-X-Trace: news.uni-berlin.de MOqHXDWrYOo2dtBaByg8lw156RFrjenl0E9qkrV3A5QxreQlPOJr92caAy Cancel-Lock: sha1:fqtTsM8ufYJFofx61iR0JNrS1g0= In-Reply-To: Mail-Followup-To: anselm.helbig+news2009@googlemail.com Original-Xref: news.stanford.edu gnu.emacs.help:170313 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:65529 Archived-At: At Thu, 25 Jun 2009 15:27:19 -0700, Sarir Khamsi wrote: > > I wrote a simple predicate that returns t if the Emacs major version > number is greater than 22 and would like some advice/comments: > > The following > > (defun sk-emacs-version-greater-than23-p () > "Return non-nil if current Emacs version is greater than 22." > (interactive) > (setq version-string (replace-regexp-in-string ".*?\\([0-9]+\\)\.\\([0-9]+\\)\.\\([0-9]+\\)[()-.a-zA-Z0-9 \n]+" "\\1 \\2 \\3" (emacs-version))) > (setq version-num (mapcar 'string-to-number (split-string version-string))) > (if (> 22 (car version-num)) > t > nil)) I hope you're not too disappointed, but there's a constant named emacs-major-version: (> emacs-major-version 22) This is also extracted from the string in emacs-version, this is how the emacs devs did it: (defconst emacs-major-version (progn (string-match "^[0-9]+" emacs-version) (string-to-number (match-string 0 emacs-version))) "Major version number of this version of Emacs. This variable first existed in version 19.23.") If you want to parse the version number yourself, this is how I would do it: (mapcar 'string-to-number (split-string emacs-version "\\.")) Note that the emacs-version variable just holds the number. This makes things a lot easier. Generally you shouldnt rely on the version number to test if a feature is available - just test directly for the feature you need. Regards, Anselm -- Anselm Helbig mailto:anselm.helbig+news2009@googlemail.com