all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: emacs-devel@gnu.org
Subject: Re: Cleaning up further compat code
Date: Sun, 03 Apr 2016 21:09:04 +0200	[thread overview]
Message-ID: <m3vb3yqzlb.fsf@gnus.org> (raw)
In-Reply-To: <m3wpoey7mf.fsf@gnus.org> (Lars Magne Ingebrigtsen's message of "Sun, 03 Apr 2016 18:33:44 +0200")

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	other threads:[~2016-04-03 19:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-03 16:29 Cleaning up further compat code Lars Magne Ingebrigtsen
2016-04-03 16:33 ` Lars Magne Ingebrigtsen
2016-04-03 19:09   ` Lars Magne Ingebrigtsen [this message]
2016-04-03 23:21     ` John Wiegley
2016-04-03 16:54 ` Michael Albinus
2016-04-04  7:06 ` Lars Magne Ingebrigtsen
2016-04-04  7:31   ` Michael Albinus
2016-04-04  7:56     ` Lars Magne Ingebrigtsen
2016-04-04 12:35   ` Stefan Monnier
2016-04-04 15:04     ` Eli Zaretskii
2016-04-04 18:13     ` Lars Magne Ingebrigtsen
2016-04-05  0:20       ` Stefan Monnier
2016-04-06 11:30         ` Lars Magne Ingebrigtsen
2016-04-05  0:16 ` Xue Fuqiao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3vb3yqzlb.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.