From: Dmitry Antipov <dmantipov@yandex.ru>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: Re: Trying coccinelle
Date: Fri, 22 Jun 2012 09:57:41 +0400 [thread overview]
Message-ID: <4FE40955.1030105@yandex.ru> (raw)
In-Reply-To: <jwv8vfjzauy.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 104 bytes --]
Here is another cleanup of some buffer-related
code designed with the help from this nice tool.
Dmitry
[-- Attachment #2: buffer_cleanup.patch --]
[-- Type: text/plain, Size: 5868 bytes --]
=== modified file 'src/buffer.c'
--- src/buffer.c 2012-06-18 07:20:19 +0000
+++ src/buffer.c 2012-06-22 05:34:23 +0000
@@ -1049,14 +1049,7 @@
register struct buffer *buf;
register Lisp_Object result;
- if (NILP (buffer))
- buf = current_buffer;
- else
- {
- CHECK_BUFFER (buffer);
- buf = XBUFFER (buffer);
- }
-
+ buf = buffer_or_current (buffer);
result = buffer_lisp_local_variables (buf);
/* Add on all the variables stored in special slots. */
@@ -1091,15 +1084,7 @@
No argument or nil as argument means use current buffer as BUFFER. */)
(register Lisp_Object buffer)
{
- register struct buffer *buf;
- if (NILP (buffer))
- buf = current_buffer;
- else
- {
- CHECK_BUFFER (buffer);
- buf = XBUFFER (buffer);
- }
-
+ register struct buffer *buf = buffer_or_current (buffer);
return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil;
}
@@ -1208,16 +1193,7 @@
No argument or nil as argument means use current buffer as BUFFER. */)
(register Lisp_Object buffer)
{
- register struct buffer *buf;
- if (NILP (buffer))
- buf = current_buffer;
- else
- {
- CHECK_BUFFER (buffer);
- buf = XBUFFER (buffer);
- }
-
- return make_number (BUF_MODIFF (buf));
+ return make_number (BUF_MODIFF (buffer_or_current (buffer)));
}
DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick,
@@ -1232,16 +1208,7 @@
buffer as BUFFER. */)
(register Lisp_Object buffer)
{
- register struct buffer *buf;
- if (NILP (buffer))
- buf = current_buffer;
- else
- {
- CHECK_BUFFER (buffer);
- buf = XBUFFER (buffer);
- }
-
- return make_number (BUF_CHARS_MODIFF (buf));
+ return make_number (BUF_CHARS_MODIFF (buffer_or_current (buffer)));
}
\f
DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2,
@@ -3580,17 +3547,11 @@
(Lisp_Object beg, Lisp_Object end, Lisp_Object buffer, Lisp_Object front_advance, Lisp_Object rear_advance)
{
Lisp_Object overlay;
- struct buffer *b;
+ struct buffer *b = buffer_or_current (buffer);
- if (NILP (buffer))
- XSETBUFFER (buffer, current_buffer);
- else
- CHECK_BUFFER (buffer);
- if (MARKERP (beg)
- && ! EQ (Fmarker_buffer (beg), buffer))
+ if (MARKERP (beg) && XMARKER (beg)->buffer != b)
error ("Marker points into wrong buffer");
- if (MARKERP (end)
- && ! EQ (Fmarker_buffer (end), buffer))
+ if (MARKERP (end) && XMARKER (end)->buffer != b)
error ("Marker points into wrong buffer");
CHECK_NUMBER_COERCE_MARKER (beg);
@@ -3602,8 +3563,7 @@
temp = beg; beg = end; end = temp;
}
- b = XBUFFER (buffer);
-
+ XSETBUFFER (buffer, b);
beg = Fset_marker (Fmake_marker (), beg, buffer);
end = Fset_marker (Fmake_marker (), end, buffer);
@@ -3705,18 +3665,14 @@
CHECK_OVERLAY (overlay);
if (NILP (buffer))
buffer = Fmarker_buffer (OVERLAY_START (overlay));
- if (NILP (buffer))
- XSETBUFFER (buffer, current_buffer);
- CHECK_BUFFER (buffer);
+ b = buffer_or_current (buffer);
- if (NILP (Fbuffer_live_p (buffer)))
+ if (NILP (BVAR (b, name)))
error ("Attempt to move overlay to a dead buffer");
- if (MARKERP (beg)
- && ! EQ (Fmarker_buffer (beg), buffer))
+ if (MARKERP (beg) && XMARKER (beg)->buffer != b)
error ("Marker points into wrong buffer");
- if (MARKERP (end)
- && ! EQ (Fmarker_buffer (end), buffer))
+ if (MARKERP (end) && XMARKER (end)->buffer != b)
error ("Marker points into wrong buffer");
CHECK_NUMBER_COERCE_MARKER (beg);
@@ -3731,7 +3687,6 @@
specbind (Qinhibit_quit, Qt);
obuffer = Fmarker_buffer (OVERLAY_START (overlay));
- b = XBUFFER (buffer);
if (!NILP (obuffer))
{
=== modified file 'src/buffer.h'
--- src/buffer.h 2012-06-16 12:24:15 +0000
+++ src/buffer.h 2012-06-22 05:37:28 +0000
@@ -886,6 +886,17 @@
extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
extern void mmap_set_vars (int);
+/* Get buffer pointer from BUF, or current buffer pointer if BUF is nil. */
+
+static inline struct buffer *
+buffer_or_current (Lisp_Object buf)
+{
+ if (NILP (buf))
+ return current_buffer;
+ CHECK_BUFFER (buf);
+ return XBUFFER (buf);
+}
+
/* Get overlays at POSN into array OVERLAYS with NOVERLAYS elements.
If NEXTP is non-NULL, return next overlay there.
See overlay_at arg CHANGE_REQ for meaning of CHRQ arg. */
=== modified file 'src/data.c'
--- src/data.c 2012-06-19 16:56:28 +0000
+++ src/data.c 2012-06-22 04:55:54 +0000
@@ -1827,14 +1827,7 @@
register struct buffer *buf;
struct Lisp_Symbol *sym;
- if (NILP (buffer))
- buf = current_buffer;
- else
- {
- CHECK_BUFFER (buffer);
- buf = XBUFFER (buffer);
- }
-
+ buf = buffer_or_current (buffer);
CHECK_SYMBOL (variable);
sym = XSYMBOL (variable);
=== modified file 'src/fileio.c'
--- src/fileio.c 2012-06-20 21:20:06 +0000
+++ src/fileio.c 2012-06-22 04:55:59 +0000
@@ -5081,13 +5081,7 @@
Lisp_Object handler;
Lisp_Object filename;
- if (NILP (buf))
- b = current_buffer;
- else
- {
- CHECK_BUFFER (buf);
- b = XBUFFER (buf);
- }
+ b = buffer_or_current (buf);
if (!STRINGP (BVAR (b, filename))) return Qt;
if (b->modtime == 0) return Qt;
=== modified file 'src/xdisp.c'
--- src/xdisp.c 2012-06-19 06:49:50 +0000
+++ src/xdisp.c 2012-06-22 05:09:06 +0000
@@ -19816,15 +19816,9 @@
See also `bidi-paragraph-direction'. */)
(Lisp_Object buffer)
{
- struct buffer *buf = current_buffer;
+ struct buffer *buf = buffer_or_current (buffer);
struct buffer *old = buf;
- if (! NILP (buffer))
- {
- CHECK_BUFFER (buffer);
- buf = XBUFFER (buffer);
- }
-
if (NILP (BVAR (buf, bidi_display_reordering))
|| NILP (BVAR (buf, enable_multibyte_characters))
/* When we are loading loadup.el, the character property tables
next prev parent reply other threads:[~2012-06-22 5:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-18 16:44 Trying coccinelle Dmitry Antipov
2012-06-18 19:47 ` Aurélien Aptel
2012-06-18 20:33 ` Stefan Monnier
2012-06-19 4:27 ` Dmitry Antipov
2012-06-19 13:31 ` Stefan Monnier
2012-06-22 5:57 ` Dmitry Antipov [this message]
2012-06-22 6:40 ` Miles Bader
2012-06-22 10:22 ` martin rudalics
2012-06-22 19:02 ` Stefan Monnier
2012-06-24 16:20 ` Dmitry Antipov
2012-06-24 18:59 ` Stefan Monnier
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=4FE40955.1030105@yandex.ru \
--to=dmantipov@yandex.ru \
--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.