Skip to content

Commit

Permalink
mac ligature fix from railwaycat emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
minimal committed Nov 4, 2015
1 parent 54e2ed9 commit 812dd51
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ enum
/* Return the raw 8-bit byte for character C. */
#define CHAR_TO_BYTE8(c) (CHAR_BYTE8_P (c) ? (c) - 0x3FFF00 : (c & 0xFF))


/* Return the raw 8-bit byte for character C,
or -1 if C doesn't correspond to a byte. */
#define CHAR_TO_BYTE_SAFE(c) \
Expand All @@ -121,6 +122,9 @@ enum
/* This is the maximum byte length of multibyte form. */
#define MAX_MULTIBYTE_LENGTH 5

/* Nonzero iff C is an ASCII byte. */
#define ASCII_BYTE_P(c) UNSIGNED_CMP (c, <, 0x80)

/* Nonzero iff X is a character. */
#define CHARACTERP(x) (NATNUMP (x) && XFASTINT (x) <= MAX_CHAR)

Expand Down
37 changes: 31 additions & 6 deletions src/composite.c
Original file line number Diff line number Diff line change
Expand Up @@ -1727,20 +1727,45 @@ should be ignored. */)

if (NILP (string))
{
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
error ("Attempt to shape unibyte text");

validate_region (&from, &to);
frompos = XFASTINT (from);
topos = XFASTINT (to);
frombyte = CHAR_TO_BYTE (frompos);
if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
frombyte = CHAR_TO_BYTE (frompos);
else
{
ptrdiff_t pos;

/* fill_gstring_header below uses
FETCH_CHAR_ADVANCE_NO_CHECK that assumes the current
buffer is multibyte, but it is safe as long as it only
fetches ASCII chars. */
for (pos = frompos; pos < topos; pos++)
if (!ASCII_BYTE_P (*(BYTE_POS_ADDR (pos))))
error ("Attempt to shape non-ASCII part of unibyte text");
frombyte = frompos;
}
}
else
{
CHECK_STRING (string);
validate_subarray (string, from, to, SCHARS (string), &frompos, &topos);
if (! STRING_MULTIBYTE (string))
error ("Attempt to shape unibyte text");
frombyte = string_char_to_byte (string, frompos);
if (STRING_MULTIBYTE (string))
frombyte = string_char_to_byte (string, frompos);
else
{
ptrdiff_t pos;

/* fill_gstring_header below uses
FETCH_STRING_CHAR_ADVANCE_NO_CHECK that assumes the
string is multibyte, but it is safe as long as it only
fetches ASCII chars. */
for (pos = frompos; pos < topos; pos++)
if (!ASCII_BYTE_P (SREF (string, pos)))
error ("Attempt to shape non-ASCII part of unibyte text");
frombyte = frompos;
}
}

header = fill_gstring_header (Qnil, frompos, frombyte,
Expand Down

0 comments on commit 812dd51

Please sign in to comment.