Re: [Emacs] Kommentieren
- From: Andreas Röhler <andreas.roehler@xxxxxxxxx>
- Date: Mon, 31 Mar 2008 20:36:04 +0200
Sven Joachim schrieb:
Hallo Andreas,
Am 31.03.2008 um 18:58 schrieb Andreas Röhler:
Das wird wohl noch gebraucht vom GNU ...
(unless (featurep 'xemacs)
(defun region-active-p ()
"and mark-active transient-mark-mode
(not (eq (region-beginning) (region-end)"
(and mark-active transient-mark-mode
(not (eq (region-beginning) (region-end))))))
Nicht nur das, »string-strip« kennt mein Emacs auch nicht.
Sven
Dank für den Hinweis. Das braucht auch XEmacs noch.
Andreas
;;; string-strip.el --- Strip CHARS from STRING
;; Version: 1.2
;; Copyright (C) 2007 Andreas Roehler
;; Author: Andreas Roehler <andreas.roehler@xxxxxxxxxxxxx>
;; Keywords: convenience
;; This file 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 3, or (at your option) any later version.
;; This file 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.
;;; Commentary:
;; Detected `comment-string-strip' in Stefan Monier's
;; newcomment.el, which worked fine so far. However,
;; it requires handling of three arguments, where just
;; one was sufficient in the cases I needed it.
;; Meanwhile a discussion in emacs-devel took place, which was
;; helpful in many respects. You may view it at
;; http://lists.gnu.org/archive/html/emacs-devel/2006-06/msg00470.html
;; Lars Hansen <lists@xxxxxxx> provided a regexp for
;; the case, the string may be composed of (and
;; preserve) newlines. In the context given now set
;; `string-chars-preserve' to "\\(\\(?:.\\|\n\\)*?\\)"
;; if you need this.
;; Finally I found it useful, not just to make the ends
;; customizable, but the middle part too: Now its
;; completely up to the user to decide, what the string
;; should contain and what chars are to strip from it.
;; (string-strip " foo ") -> "foo" shows the default-behavior
;; You may specify args on the fly, which will override it, thus
;; (string-strip "[:blank:]" "\\[:" ":\\]") -> "blank"
;; (string-strip "[:blank:]" "\\[:.*" ":\\]" "\\(a.+\\)") -> "ank"
;; Changes to previous version:
;; Let optional arguments overrid defaults, interactive
;; spec dropped as it seems not useful, Doku renewed
;;; History:
;;
;;; Code:
;; (setq strip-chars-before "[ \t\r\n\f]*")
(defcustom strip-chars-before "[ \t\r\n\f]*"
"Regexp indicating which chars shall be stripped before STRING - which is defined by `string-chars-preserve'."
:type 'string
:group 'convenience)
;; (setq strip-chars-after "[ \t\r\n\f]*")
(defcustom strip-chars-after "[ \t\r\n\f]*\\'"
"Regexp indicating which chars shall be stripped after STRING - which is defined by `string-chars-preserve'."
:type 'string
:group 'convenience)
(defcustom string-chars-preserve "\\(.*?\\)"
"Chars preserved of STRING.
`strip-chars-after' and
`strip-chars-before' indicate what class of chars to strip."
:type 'string
:group 'convenience)
(defun string-strip (str &optional chars-before chars-after chars-preserve)
"Return a copy of STR, CHARS removed.
`CHARS-BEFORE' and `CHARS-AFTER' default is \"[ \t\r\n\f]*\",
i.e. spaces, tabs, carriage returns, newlines and newpages.
`CHARS-PRESERVE' must be a parentized expression,
it defaults to \"\\(.*?\\)\""
(let ((s-c-b (or chars-before
strip-chars-before))
(s-c-a (or chars-after
strip-chars-after))
(s-c-p (or chars-preserve
string-chars-preserve)))
(string-match
(concat "\\`[" s-c-b"]*" s-c-p "[" s-c-a "]*\\'") str)
(match-string 1 str)))
(provide 'string-strip)
;;; string-strip.el ends here
- Follow-Ups:
- Re: [Emacs] Kommentieren
- From: Sven Joachim
- Re: [Emacs] Kommentieren
- References:
- [Emacs] Kommentieren
- From: Andreas Röhler
- Re: [Emacs] Kommentieren
- From: Andreas Röhler
- Re: [Emacs] Kommentieren
- From: Sven Joachim
- [Emacs] Kommentieren
- Prev by Date: Re: [Emacs] Kommentieren
- Next by Date: Re: [Emacs] Kommentieren
- Previous by thread: Re: [Emacs] Kommentieren
- Next by thread: Re: [Emacs] Kommentieren
- Index(es):
Relevant Pages
|