emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tiny change to find-tag-default.


From: martin rudalics
Subject: Re: Tiny change to find-tag-default.
Date: Sat, 22 Jul 2006 14:17:55 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Wouldn't it make sense to rewrite the rest of `find-tag-default' too?
In its current version it unnecessarily clobbers `match-data', requires
a `condition-case' to handle errors in `forward-sexp', and has other
tedious things like repeated forward-charing and re-searching.

I'm using the attached version for approximately half a year and didn't
encounter any problems so far.

*** subr.el     Tue Jun  6 19:20:26 2006
--- subr.el     Mon Jul 10 11:42:40 2006
***************
*** 1949,1973 ****
    "Determine default tag to search for, based on text at point.
  If there is no plausible default, return nil."
    (save-excursion
!     (while (looking-at "\\sw\\|\\s_")
!       (forward-char 1))
!     (if (or (re-search-backward "\\sw\\|\\s_"
!                               (save-excursion (beginning-of-line) (point))
!                               t)
!           (re-search-forward "\\(\\sw\\|\\s_\\)+"
!                              (save-excursion (end-of-line) (point))
!                              t))
!       (progn
!         (goto-char (match-end 0))
!         (condition-case nil
!             (buffer-substring-no-properties
!              (point)
!              (progn (forward-sexp -1)
!                     (while (looking-at "\\s'")
!                       (forward-char 1))
!                     (point)))
!           (error nil)))
!       nil)))

  (defun play-sound (sound)
    "SOUND is a list of the form `(sound KEYWORD VALUE...)'.
--- 1949,1973 ----
    "Determine default tag to search for, based on text at point.
  If there is no plausible default, return nil."
    (save-excursion
!     (let (from to bound)
!       (when (or (and (save-excursion
!                      (skip-syntax-backward "w_") (setq from (point)))
!                    (save-excursion
!                      (skip-syntax-forward "w_") (setq to (point)))
!                    (> to from))
!               ;; Look between `line-beginning-position' and `point'.
!               (and (setq bound (line-beginning-position))
!                    (skip-syntax-backward "^w_" bound)
!                    (> (setq to (point)) bound)
!                    (skip-syntax-backward "w_")
!                    (setq from (point)))
!               ;; Look between `point' and `line-end-position'.
!               (and (setq bound (line-end-position))
!                    (skip-syntax-forward "^w_" bound)
!                    (< (setq from (point)) bound)
!                    (skip-syntax-forward "w_")
!                    (setq to (point))))
!         (buffer-substring-no-properties from to)))))

  (defun play-sound (sound)
    "SOUND is a list of the form `(sound KEYWORD VALUE...)'.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]