emacs-devel
[Top][All Lists]
Advanced

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

Re: Cleaning up further compat code


From: Lars Magne Ingebrigtsen
Subject: Re: Cleaning up further compat code
Date: Sun, 03 Apr 2016 21:09:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

I guess we should put off doing cleanups until Emacs 25.1 has been
released, because merging between the branches get kinda hairy if you
change the trunk a lot.

But anyway, I thought I'd just post the two functions that I was using
to do

(if (featurep 'xemacs)
    (something)
  (something)
  (else))

cleanup, in case somebody wants to do some cleanup.  The first deletes
the "then" part, and the second deletes the "else" part (which is useful
when it's (if (featurep 'emacs) ...)  instead).

Of course, you have to see whether the code makes sense afterwards.
Which is might not if the code is (setq foo (if ...)), for instance.

(defun lars-delete-then ()
  "Delete the if statement and the then statement."
  (interactive)
  (if (looking-at " *(if")
      (delete-region (point) (match-end 0))
    (search-backward "(if" (line-beginning-position))
    (delete-region (point) (+ (point) 3)))
  (kill-sexp 2)
  (save-excursion
    (while (ignore-errors
             (forward-sexp 1)
             t))
    ;; Delete the final ")".
    (delete-region (point) (1+ (point))))
  (save-excursion
    (beginning-of-line)
    (when (looking-at "\\s-*$")
      (delete-region (point) (line-beginning-position 2))))
  (save-excursion
    (search-backward "(")
    (indent-sexp)))

(defun lars-delete-else ()
  "Delete the if statement and the else statement."
  (interactive)
  (if (looking-at " *(if")
      (delete-region (point) (match-end 0))
    (search-backward "(if" (line-beginning-position))
    (delete-region (point) (+ (point) 3)))
  (kill-sexp 1)
  (let ((start (point)))
    (forward-sexp 1)
    (while (ignore-errors
             (kill-sexp 1)
             t))
    ;; Delete the final ")".
    (delete-region (point) (1+ (point)))
    (goto-char start)
    (save-excursion
      (beginning-of-line)
      (when (looking-at "\\s-*$")
        (delete-region (point) (line-beginning-position 2))))
    (save-excursion
      (search-backward "(")
      (indent-sexp))))

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




reply via email to

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