aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrea Corallo2020-09-26 15:31:50 +0200
committerAndrea Corallo2020-09-26 15:31:50 +0200
commit06acf681d6fd8e2c5c6a9584b5df6b98eccda20b (patch)
tree5cc7132156db6b77599a86072de21a036828bcf4 /src
parente5b052d60d905209c6cefcf18c620167ed946301 (diff)
parente00936bf9f10cf44e1df71a7a11afd770e8a122a (diff)
downloademacs-06acf681d6fd8e2c5c6a9584b5df6b98eccda20b.tar.gz
emacs-06acf681d6fd8e2c5c6a9584b5df6b98eccda20b.zip
Merge remote-tracking branch 'savannah/master' into HEAD
Diffstat (limited to 'src')
-rw-r--r--src/dbusbind.c139
-rw-r--r--src/fns.c52
-rw-r--r--src/nsfont.m240
-rw-r--r--src/nsimage.m12
-rw-r--r--src/nsterm.h41
-rw-r--r--src/nsterm.m105
-rw-r--r--src/process.c39
-rw-r--r--src/syntax.c7
-rw-r--r--src/xdisp.c13
9 files changed, 294 insertions, 354 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c
index 4c5ab485803..09f0317be91 100644
--- a/src/dbusbind.c
+++ b/src/dbusbind.c
@@ -44,7 +44,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
44 44
45/* Alist of D-Bus buses we are polling for messages. 45/* Alist of D-Bus buses we are polling for messages.
46 The key is the symbol or string of the bus, and the value is the 46 The key is the symbol or string of the bus, and the value is the
47 connection address. */ 47 connection address. For every bus, just one connection is counted.
48 If there shall be a second connection to the same bus, a different
49 symbol or string for the bus must be chosen. On Lisp level, a bus
50 stands for the associated connection. */
48static Lisp_Object xd_registered_buses; 51static Lisp_Object xd_registered_buses;
49 52
50/* Whether we are reading a D-Bus event. */ 53/* Whether we are reading a D-Bus event. */
@@ -279,10 +282,13 @@ XD_OBJECT_TO_STRING (Lisp_Object object)
279 else \ 282 else \
280 { \ 283 { \
281 CHECK_SYMBOL (bus); \ 284 CHECK_SYMBOL (bus); \
282 if (!(EQ (bus, QCsystem) || EQ (bus, QCsession))) \ 285 if (!(EQ (bus, QCsystem) || EQ (bus, QCsession) \
286 || EQ (bus, QCsystem_private) \
287 || EQ (bus, QCsession_private))) \
283 XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ 288 XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \
284 /* We do not want to have an autolaunch for the session bus. */ \ 289 /* We do not want to have an autolaunch for the session bus. */ \
285 if (EQ (bus, QCsession) && session_bus_address == NULL) \ 290 if ((EQ (bus, QCsession) || EQ (bus, QCsession_private)) \
291 && session_bus_address == NULL) \
286 XD_SIGNAL2 (build_string ("No connection to bus"), bus); \ 292 XD_SIGNAL2 (build_string ("No connection to bus"), bus); \
287 } \ 293 } \
288 } while (0) 294 } while (0)
@@ -968,8 +974,9 @@ xd_lisp_dbus_to_dbus (Lisp_Object bus)
968 return xmint_pointer (bus); 974 return xmint_pointer (bus);
969} 975}
970 976
971/* Return D-Bus connection address. BUS is either a Lisp symbol, 977/* Return D-Bus connection address.
972 :system or :session, or a string denoting the bus address. */ 978 BUS is either a Lisp symbol, :system, :session, :system-private or
979 :session-private, or a string denoting the bus address. */
973static DBusConnection * 980static DBusConnection *
974xd_get_connection_address (Lisp_Object bus) 981xd_get_connection_address (Lisp_Object bus)
975{ 982{
@@ -1031,7 +1038,8 @@ xd_add_watch (DBusWatch *watch, void *data)
1031} 1038}
1032 1039
1033/* Stop monitoring WATCH for possible I/O. 1040/* Stop monitoring WATCH for possible I/O.
1034 DATA is the used bus, either a string or QCsystem or QCsession. */ 1041 DATA is the used bus, either a string or QCsystem, QCsession,
1042 QCsystem_private or QCsession_private. */
1035static void 1043static void
1036xd_remove_watch (DBusWatch *watch, void *data) 1044xd_remove_watch (DBusWatch *watch, void *data)
1037{ 1045{
@@ -1046,7 +1054,7 @@ xd_remove_watch (DBusWatch *watch, void *data)
1046 /* Unset session environment. */ 1054 /* Unset session environment. */
1047#if 0 1055#if 0
1048 /* This is buggy, since unsetenv is not thread-safe. */ 1056 /* This is buggy, since unsetenv is not thread-safe. */
1049 if (XSYMBOL (QCsession) == data) 1057 if (XSYMBOL (QCsession) == data) || (XSYMBOL (QCsession_private) == data)
1050 { 1058 {
1051 XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS"); 1059 XD_DEBUG_MESSAGE ("unsetenv DBUS_SESSION_BUS_ADDRESS");
1052 unsetenv ("DBUS_SESSION_BUS_ADDRESS"); 1060 unsetenv ("DBUS_SESSION_BUS_ADDRESS");
@@ -1120,6 +1128,11 @@ can be a string denoting the address of the corresponding bus. For
1120the system and session buses, this function is called when loading 1128the system and session buses, this function is called when loading
1121`dbus.el', there is no need to call it again. 1129`dbus.el', there is no need to call it again.
1122 1130
1131A special case is BUS being the symbol `:system-private' or
1132`:session-private'. These symbols still denote the system or session
1133bus, but using a private connection. They should not be used outside
1134dbus.el.
1135
1123The function returns a number, which counts the connections this Emacs 1136The function returns a number, which counts the connections this Emacs
1124session has established to the BUS under the same unique name (see 1137session has established to the BUS under the same unique name (see
1125`dbus-get-unique-name'). It depends on the libraries Emacs is linked 1138`dbus-get-unique-name'). It depends on the libraries Emacs is linked
@@ -1142,6 +1155,10 @@ this connection to those buses. */)
1142 ptrdiff_t refcount; 1155 ptrdiff_t refcount;
1143 1156
1144 /* Check parameter. */ 1157 /* Check parameter. */
1158 if (!NILP (private))
1159 bus = EQ (bus, QCsystem)
1160 ? QCsystem_private
1161 : EQ (bus, QCsession) ? QCsession_private : bus;
1145 XD_DBUS_VALIDATE_BUS_ADDRESS (bus); 1162 XD_DBUS_VALIDATE_BUS_ADDRESS (bus);
1146 1163
1147 /* Close bus if it is already open. */ 1164 /* Close bus if it is already open. */
@@ -1169,8 +1186,9 @@ this connection to those buses. */)
1169 1186
1170 else 1187 else
1171 { 1188 {
1172 DBusBusType bustype = (EQ (bus, QCsystem) 1189 DBusBusType bustype
1173 ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION); 1190 = EQ (bus, QCsystem) || EQ (bus, QCsystem_private)
1191 ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION;
1174 if (NILP (private)) 1192 if (NILP (private))
1175 connection = dbus_bus_get (bustype, &derror); 1193 connection = dbus_bus_get (bustype, &derror);
1176 else 1194 else
@@ -1184,9 +1202,9 @@ this connection to those buses. */)
1184 XD_SIGNAL2 (build_string ("No connection to bus"), bus); 1202 XD_SIGNAL2 (build_string ("No connection to bus"), bus);
1185 1203
1186 /* If it is not the system or session bus, we must register 1204 /* If it is not the system or session bus, we must register
1187 ourselves. Otherwise, we have called dbus_bus_get, which has 1205 ourselves. Otherwise, we have called dbus_bus_get{_private},
1188 configured us to exit if the connection closes - we undo this 1206 which has configured us to exit if the connection closes - we
1189 setting. */ 1207 undo this setting. */
1190 if (STRINGP (bus)) 1208 if (STRINGP (bus))
1191 dbus_bus_register (connection, &derror); 1209 dbus_bus_register (connection, &derror);
1192 else 1210 else
@@ -1215,6 +1233,9 @@ this connection to those buses. */)
1215 dbus_error_free (&derror); 1233 dbus_error_free (&derror);
1216 } 1234 }
1217 1235
1236 XD_DEBUG_MESSAGE ("Registered buses: %s",
1237 XD_OBJECT_TO_STRING (xd_registered_buses));
1238
1218 /* Return reference counter. */ 1239 /* Return reference counter. */
1219 refcount = xd_get_connection_references (connection); 1240 refcount = xd_get_connection_references (connection);
1220 XD_DEBUG_MESSAGE ("Bus %s, Reference counter %"pD"d", 1241 XD_DEBUG_MESSAGE ("Bus %s, Reference counter %"pD"d",
@@ -1533,8 +1554,8 @@ usage: (dbus-message-internal &rest REST) */)
1533} 1554}
1534 1555
1535/* Read one queued incoming message of the D-Bus BUS. 1556/* Read one queued incoming message of the D-Bus BUS.
1536 BUS is either a Lisp symbol, :system or :session, or a string denoting 1557 BUS is either a Lisp symbol, :system, :session, :system-private or
1537 the bus address. */ 1558 :session-private, or a string denoting the bus address. */
1538static void 1559static void
1539xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) 1560xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1540{ 1561{
@@ -1546,7 +1567,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1546 int mtype; 1567 int mtype;
1547 dbus_uint32_t serial; 1568 dbus_uint32_t serial;
1548 unsigned int ui_serial; 1569 unsigned int ui_serial;
1549 const char *uname, *path, *interface, *member, *error_name; 1570 const char *uname, *destination, *path, *interface, *member, *error_name;
1550 1571
1551 dmessage = dbus_connection_pop_message (connection); 1572 dmessage = dbus_connection_pop_message (connection);
1552 1573
@@ -1579,6 +1600,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1579 ? dbus_message_get_reply_serial (dmessage) 1600 ? dbus_message_get_reply_serial (dmessage)
1580 : dbus_message_get_serial (dmessage); 1601 : dbus_message_get_serial (dmessage);
1581 uname = dbus_message_get_sender (dmessage); 1602 uname = dbus_message_get_sender (dmessage);
1603 destination = dbus_message_get_destination (dmessage);
1582 path = dbus_message_get_path (dmessage); 1604 path = dbus_message_get_path (dmessage);
1583 interface = dbus_message_get_interface (dmessage); 1605 interface = dbus_message_get_interface (dmessage);
1584 member = dbus_message_get_member (dmessage); 1606 member = dbus_message_get_member (dmessage);
@@ -1586,7 +1608,8 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1586 1608
1587 XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s %s", 1609 XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s %s",
1588 XD_MESSAGE_TYPE_TO_STRING (mtype), 1610 XD_MESSAGE_TYPE_TO_STRING (mtype),
1589 ui_serial, uname, path, interface, member, error_name, 1611 ui_serial, uname, destination, path, interface,
1612 mtype == DBUS_MESSAGE_TYPE_ERROR ? error_name : member,
1590 XD_OBJECT_TO_STRING (args)); 1613 XD_OBJECT_TO_STRING (args));
1591 1614
1592 if (mtype == DBUS_MESSAGE_TYPE_INVALID) 1615 if (mtype == DBUS_MESSAGE_TYPE_INVALID)
@@ -1601,7 +1624,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1601 1624
1602 /* There shall be exactly one entry. Construct an event. */ 1625 /* There shall be exactly one entry. Construct an event. */
1603 if (NILP (value)) 1626 if (NILP (value))
1604 goto cleanup; 1627 goto monitor;
1605 1628
1606 /* Remove the entry. */ 1629 /* Remove the entry. */
1607 Fremhash (key, Vdbus_registered_objects_table); 1630 Fremhash (key, Vdbus_registered_objects_table);
@@ -1610,11 +1633,8 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1610 EVENT_INIT (event); 1633 EVENT_INIT (event);
1611 event.kind = DBUS_EVENT; 1634 event.kind = DBUS_EVENT;
1612 event.frame_or_window = Qnil; 1635 event.frame_or_window = Qnil;
1613 event.arg = 1636 /* Handler. */
1614 Fcons (value, 1637 event.arg = Fcons (value, args);
1615 (mtype == DBUS_MESSAGE_TYPE_ERROR)
1616 ? Fcons (list2 (QCstring, build_string (error_name)), args)
1617 : args);
1618 } 1638 }
1619 1639
1620 else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */ 1640 else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */
@@ -1622,7 +1642,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1622 /* Vdbus_registered_objects_table requires non-nil interface and 1642 /* Vdbus_registered_objects_table requires non-nil interface and
1623 member. */ 1643 member. */
1624 if ((interface == NULL) || (member == NULL)) 1644 if ((interface == NULL) || (member == NULL))
1625 goto cleanup; 1645 goto monitor;
1626 1646
1627 /* Search for a registered function of the message. */ 1647 /* Search for a registered function of the message. */
1628 key = list4 (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL ? QCmethod : QCsignal, 1648 key = list4 (mtype == DBUS_MESSAGE_TYPE_METHOD_CALL ? QCmethod : QCsignal,
@@ -1647,6 +1667,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1647 EVENT_INIT (event); 1667 EVENT_INIT (event);
1648 event.kind = DBUS_EVENT; 1668 event.kind = DBUS_EVENT;
1649 event.frame_or_window = Qnil; 1669 event.frame_or_window = Qnil;
1670 /* Handler. */
1650 event.arg 1671 event.arg
1651 = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))), args); 1672 = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (key)))), args);
1652 break; 1673 break;
@@ -1655,16 +1676,22 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1655 } 1676 }
1656 1677
1657 if (NILP (value)) 1678 if (NILP (value))
1658 goto cleanup; 1679 goto monitor;
1659 } 1680 }
1660 1681
1661 /* Add type, serial, uname, path, interface and member to the event. */ 1682 /* Add type, serial, uname, destination, path, interface and member
1662 event.arg = Fcons ((member == NULL ? Qnil : build_string (member)), 1683 or error_name to the event. */
1663 event.arg); 1684 event.arg
1685 = Fcons (mtype == DBUS_MESSAGE_TYPE_ERROR
1686 ? error_name == NULL ? Qnil : build_string (error_name)
1687 : member == NULL ? Qnil : build_string (member),
1688 event.arg);
1664 event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)), 1689 event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)),
1665 event.arg); 1690 event.arg);
1666 event.arg = Fcons ((path == NULL ? Qnil : build_string (path)), 1691 event.arg = Fcons ((path == NULL ? Qnil : build_string (path)),
1667 event.arg); 1692 event.arg);
1693 event.arg = Fcons ((destination == NULL ? Qnil : build_string (destination)),
1694 event.arg);
1668 event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)), 1695 event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)),
1669 event.arg); 1696 event.arg);
1670 event.arg = Fcons (INT_TO_INTEGER (serial), event.arg); 1697 event.arg = Fcons (INT_TO_INTEGER (serial), event.arg);
@@ -1678,14 +1705,58 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus)
1678 1705
1679 XD_DEBUG_MESSAGE ("Event stored: %s", XD_OBJECT_TO_STRING (event.arg)); 1706 XD_DEBUG_MESSAGE ("Event stored: %s", XD_OBJECT_TO_STRING (event.arg));
1680 1707
1708 /* Monitor. */
1709 monitor:
1710 /* Search for a registered function of the message. */
1711 key = list2 (QCmonitor, bus);
1712 value = Fgethash (key, Vdbus_registered_objects_table, Qnil);
1713
1714 /* There shall be exactly one entry. Construct an event. */
1715 if (NILP (value))
1716 goto cleanup;
1717
1718 /* Construct an event. */
1719 EVENT_INIT (event);
1720 event.kind = DBUS_EVENT;
1721 event.frame_or_window = Qnil;
1722
1723 /* Add type, serial, uname, destination, path, interface, member
1724 or error_name and handler to the event. */
1725 event.arg
1726 = Fcons (CAR_SAFE (CDR_SAFE (CDR_SAFE (CDR_SAFE (CAR_SAFE (value))))),
1727 args);
1728 event.arg
1729 = Fcons (mtype == DBUS_MESSAGE_TYPE_ERROR
1730 ? error_name == NULL ? Qnil : build_string (error_name)
1731 : member == NULL ? Qnil : build_string (member),
1732 event.arg);
1733 event.arg = Fcons ((interface == NULL ? Qnil : build_string (interface)),
1734 event.arg);
1735 event.arg = Fcons ((path == NULL ? Qnil : build_string (path)),
1736 event.arg);
1737 event.arg = Fcons ((destination == NULL ? Qnil : build_string (destination)),
1738 event.arg);
1739 event.arg = Fcons ((uname == NULL ? Qnil : build_string (uname)),
1740 event.arg);
1741 event.arg = Fcons (INT_TO_INTEGER (serial), event.arg);
1742 event.arg = Fcons (make_fixnum (mtype), event.arg);
1743
1744 /* Add the bus symbol to the event. */
1745 event.arg = Fcons (bus, event.arg);
1746
1747 /* Store it into the input event queue. */
1748 kbd_buffer_store_event (&event);
1749
1750 XD_DEBUG_MESSAGE ("Monitor event stored: %s", XD_OBJECT_TO_STRING (event.arg));
1751
1681 /* Cleanup. */ 1752 /* Cleanup. */
1682 cleanup: 1753 cleanup:
1683 dbus_message_unref (dmessage); 1754 dbus_message_unref (dmessage);
1684} 1755}
1685 1756
1686/* Read queued incoming messages of the D-Bus BUS. 1757/* Read queued incoming messages of the D-Bus BUS.
1687 BUS is either a Lisp symbol, :system or :session, or a string denoting 1758 BUS is either a Lisp symbol, :system, :session, :system-private or
1688 the bus address. */ 1759 :session-private, or a string denoting the bus address. */
1689static Lisp_Object 1760static Lisp_Object
1690xd_read_message (Lisp_Object bus) 1761xd_read_message (Lisp_Object bus)
1691{ 1762{
@@ -1762,6 +1833,8 @@ syms_of_dbusbind (void)
1762 /* Lisp symbols of the system and session buses. */ 1833 /* Lisp symbols of the system and session buses. */
1763 DEFSYM (QCsystem, ":system"); 1834 DEFSYM (QCsystem, ":system");
1764 DEFSYM (QCsession, ":session"); 1835 DEFSYM (QCsession, ":session");
1836 DEFSYM (QCsystem_private, ":system-private");
1837 DEFSYM (QCsession_private, ":session-private");
1765 1838
1766 /* Lisp symbol for method call timeout. */ 1839 /* Lisp symbol for method call timeout. */
1767 DEFSYM (QCtimeout, ":timeout"); 1840 DEFSYM (QCtimeout, ":timeout");
@@ -1788,10 +1861,11 @@ syms_of_dbusbind (void)
1788 DEFSYM (QCdict_entry, ":dict-entry"); 1861 DEFSYM (QCdict_entry, ":dict-entry");
1789 1862
1790 /* Lisp symbols of objects in `dbus-registered-objects-table'. 1863 /* Lisp symbols of objects in `dbus-registered-objects-table'.
1791 `:property', which does exist there as well, is not used here. */ 1864 `:property', which does exist there as well, is not declared here. */
1792 DEFSYM (QCserial, ":serial"); 1865 DEFSYM (QCserial, ":serial");
1793 DEFSYM (QCmethod, ":method"); 1866 DEFSYM (QCmethod, ":method");
1794 DEFSYM (QCsignal, ":signal"); 1867 DEFSYM (QCsignal, ":signal");
1868 DEFSYM (QCmonitor, ":monitor");
1795 1869
1796 DEFVAR_LISP ("dbus-compiled-version", 1870 DEFVAR_LISP ("dbus-compiled-version",
1797 Vdbus_compiled_version, 1871 Vdbus_compiled_version,
@@ -1867,8 +1941,9 @@ path of the sending object. All of them can be nil, which means a
1867wildcard then. 1941wildcard then.
1868 1942
1869OBJECT is either the handler to be called when a D-Bus message, which 1943OBJECT is either the handler to be called when a D-Bus message, which
1870matches the key criteria, arrives (TYPE `:method' and `:signal'), or a 1944matches the key criteria, arrives (TYPE `:method', `:signal' and
1871list (ACCESS EMITS-SIGNAL VALUE) for TYPE `:property'. 1945`:monitor'), or a list (ACCESS EMITS-SIGNAL VALUE) for TYPE
1946`:property'.
1872 1947
1873For entries of type `:signal', there is also a fifth element RULE, 1948For entries of type `:signal', there is also a fifth element RULE,
1874which keeps the match string the signal is registered with. 1949which keeps the match string the signal is registered with.
diff --git a/src/fns.c b/src/fns.c
index a3b8d6ef57d..2f64d955760 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -5454,6 +5454,57 @@ It should not be used for anything security-related. See
5454 return make_digest_string (digest, SHA1_DIGEST_SIZE); 5454 return make_digest_string (digest, SHA1_DIGEST_SIZE);
5455} 5455}
5456 5456
5457DEFUN ("string-search", Fstring_search, Sstring_search, 2, 3, 0,
5458 doc: /* Search for the string NEEDLE in the string HAYSTACK.
5459The return value is the position of the first occurrence of NEEDLE in
5460HAYSTACK, or nil if no match was found.
5461
5462The optional START-POS argument says where to start searching in
5463HAYSTACK and defaults to zero (start at the beginning).
5464It must be between zero and the length of HAYSTACK, inclusive.
5465
5466Case is always significant and text properties are ignored. */)
5467 (register Lisp_Object needle, Lisp_Object haystack, Lisp_Object start_pos)
5468{
5469 ptrdiff_t start_byte = 0, haybytes;
5470 char *res, *haystart;
5471
5472 CHECK_STRING (needle);
5473 CHECK_STRING (haystack);
5474
5475 if (!NILP (start_pos))
5476 {
5477 CHECK_FIXNUM (start_pos);
5478 EMACS_INT start = XFIXNUM (start_pos);
5479 if (start < 0 || start > SCHARS (haystack))
5480 xsignal1 (Qargs_out_of_range, start_pos);
5481 start_byte = string_char_to_byte (haystack, start);
5482 }
5483
5484 haystart = SSDATA (haystack) + start_byte;
5485 haybytes = SBYTES (haystack) - start_byte;
5486
5487 if (STRING_MULTIBYTE (haystack) == STRING_MULTIBYTE (needle))
5488 res = memmem (haystart, haybytes,
5489 SSDATA (needle), SBYTES (needle));
5490 else if (STRING_MULTIBYTE (haystack)) /* unibyte needle */
5491 {
5492 Lisp_Object multi_needle = string_to_multibyte (needle);
5493 res = memmem (haystart, haybytes,
5494 SSDATA (multi_needle), SBYTES (multi_needle));
5495 }
5496 else /* unibyte haystack, multibyte needle */
5497 {
5498 Lisp_Object uni_needle = Fstring_as_unibyte (needle);
5499 res = memmem (haystart, haybytes,
5500 SSDATA (uni_needle), SBYTES (uni_needle));
5501 }
5502
5503 if (! res)
5504 return Qnil;
5505
5506 return make_int (string_byte_to_char (haystack, res - SSDATA (haystack)));
5507}
5457 5508
5458 5509
5459void 5510void
@@ -5494,6 +5545,7 @@ syms_of_fns (void)
5494 defsubr (&Sremhash); 5545 defsubr (&Sremhash);
5495 defsubr (&Smaphash); 5546 defsubr (&Smaphash);
5496 defsubr (&Sdefine_hash_table_test); 5547 defsubr (&Sdefine_hash_table_test);
5548 defsubr (&Sstring_search);
5497 5549
5498 /* Crypto and hashing stuff. */ 5550 /* Crypto and hashing stuff. */
5499 DEFSYM (Qiv_auto, "iv-auto"); 5551 DEFSYM (Qiv_auto, "iv-auto");
diff --git a/src/nsfont.m b/src/nsfont.m
index 691becda6da..d1543ec69ce 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -39,9 +39,7 @@ Author: Adrian Robert (arobert@cogsci.ucsd.edu)
39#include "pdumper.h" 39#include "pdumper.h"
40 40
41/* TODO: Drop once we can assume gnustep-gui 0.17.1. */ 41/* TODO: Drop once we can assume gnustep-gui 0.17.1. */
42#ifdef NS_IMPL_GNUSTEP
43#import <AppKit/NSFontDescriptor.h> 42#import <AppKit/NSFontDescriptor.h>
44#endif
45 43
46#define NSFONT_TRACE 0 44#define NSFONT_TRACE 0
47#define LCD_SMOOTHING_MARGIN 2 45#define LCD_SMOOTHING_MARGIN 2
@@ -237,12 +235,6 @@ ns_char_width (NSFont *sfont, int c)
237 CGFloat w = -1.0; 235 CGFloat w = -1.0;
238 NSString *cstr = [NSString stringWithFormat: @"%c", c]; 236 NSString *cstr = [NSString stringWithFormat: @"%c", c];
239 237
240#ifdef NS_IMPL_COCOA
241 NSGlyph glyph = [sfont glyphWithName: cstr];
242 if (glyph)
243 w = [sfont advancementForGlyph: glyph].width;
244#endif
245
246 if (w < 0.0) 238 if (w < 0.0)
247 { 239 {
248 NSDictionary *attrsDictionary = 240 NSDictionary *attrsDictionary =
@@ -273,12 +265,6 @@ ns_ascii_average_width (NSFont *sfont)
273 ascii_printable = [[NSString alloc] initWithFormat: @"%s", chars]; 265 ascii_printable = [[NSString alloc] initWithFormat: @"%s", chars];
274 } 266 }
275 267
276#ifdef NS_IMPL_COCOA
277 NSGlyph glyph = [sfont glyphWithName: ascii_printable];
278 if (glyph)
279 w = [sfont advancementForGlyph: glyph].width;
280#endif
281
282 if (w < (CGFloat) 0.0) 268 if (w < (CGFloat) 0.0)
283 { 269 {
284 NSDictionary *attrsDictionary = 270 NSDictionary *attrsDictionary =
@@ -511,10 +497,6 @@ static NSSet
511 } 497 }
512 [charset release]; 498 [charset release];
513 } 499 }
514#ifdef NS_IMPL_COCOA
515 if ([families count] == 0)
516 [families addObject: @"LastResort"];
517#endif
518 [scriptToFamilies setObject: families forKey: script]; 500 [scriptToFamilies setObject: families forKey: script];
519 } 501 }
520 502
@@ -734,11 +716,6 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
734 traits: traits & ~NSItalicFontMask 716 traits: traits & ~NSItalicFontMask
735 weight: fixLeopardBug size: pixel_size]; 717 weight: fixLeopardBug size: pixel_size];
736 } 718 }
737#ifdef NS_IMPL_COCOA
738 /* LastResort not really a family */
739 if (nsfont == nil && [@"LastResort" isEqualToString: family])
740 nsfont = [NSFont fontWithName: @"LastResort" size: pixel_size];
741#endif
742 719
743 if (nsfont == nil) 720 if (nsfont == nil)
744 { 721 {
@@ -765,12 +742,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
765 font_info->metrics = xzalloc (0x100 * sizeof *font_info->metrics); 742 font_info->metrics = xzalloc (0x100 * sizeof *font_info->metrics);
766 743
767 /* for metrics */ 744 /* for metrics */
768#ifdef NS_IMPL_COCOA
769 sfont = [nsfont screenFontWithRenderingMode:
770 NSFontAntialiasedIntegerAdvancementsRenderingMode];
771#else
772 sfont = [nsfont screenFont]; 745 sfont = [nsfont screenFont];
773#endif
774 746
775 if (sfont == nil) 747 if (sfont == nil)
776 sfont = nsfont; 748 sfont = nsfont;
@@ -797,11 +769,7 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
797 * intended. */ 769 * intended. */
798 CGFloat adjusted_descender = [sfont descender] + 0.0001; 770 CGFloat adjusted_descender = [sfont descender] + 0.0001;
799 771
800#ifdef NS_IMPL_GNUSTEP
801 font_info->nsfont = sfont; 772 font_info->nsfont = sfont;
802#else
803 font_info->nsfont = nsfont;
804#endif
805 [font_info->nsfont retain]; 773 [font_info->nsfont retain];
806 774
807 /* set up ns_font (defined in nsgui.h) */ 775 /* set up ns_font (defined in nsgui.h) */
@@ -834,32 +802,6 @@ nsfont_open (struct frame *f, Lisp_Object font_entity, int pixel_size)
834 font_info->max_bounds.rbearing = 802 font_info->max_bounds.rbearing =
835 lrint (brect.size.width - (CGFloat) font_info->width); 803 lrint (brect.size.width - (CGFloat) font_info->width);
836 804
837#ifdef NS_IMPL_COCOA
838 /* set up synthItal and the CG font */
839 font_info->synthItal = synthItal;
840 {
841 ATSFontRef atsFont = ATSFontFindFromPostScriptName
842 ((CFStringRef)[nsfont fontName], kATSOptionFlagsDefault);
843
844 if (atsFont == kATSFontRefUnspecified)
845 {
846 /* see if we can get it by dropping italic (then synthesizing) */
847 atsFont = ATSFontFindFromPostScriptName ((CFStringRef)
848 [[fontMgr convertFont: nsfont toNotHaveTrait: NSItalicFontMask]
849 fontName], kATSOptionFlagsDefault);
850 if (atsFont != kATSFontRefUnspecified)
851 font_info->synthItal = YES;
852 else
853 {
854 /* last resort fallback */
855 atsFont = ATSFontFindFromPostScriptName
856 ((CFStringRef)@"Monaco", kATSOptionFlagsDefault);
857 }
858 }
859 font_info->cgfont = CGFontCreateWithPlatformFont ((void *) &atsFont);
860 }
861#endif
862
863 /* set up metrics portion of font struct */ 805 /* set up metrics portion of font struct */
864 font->ascent = lrint([sfont ascender]); 806 font->ascent = lrint([sfont ascender]);
865 font->descent = -lrint(floor(adjusted_descender)); 807 font->descent = -lrint(floor(adjusted_descender));
@@ -901,9 +843,6 @@ nsfont_close (struct font *font)
901 xfree (font_info->glyphs); 843 xfree (font_info->glyphs);
902 xfree (font_info->metrics); 844 xfree (font_info->metrics);
903 [font_info->nsfont release]; 845 [font_info->nsfont release];
904#ifdef NS_IMPL_COCOA
905 CGFontRelease (font_info->cgfont);
906#endif
907 xfree (font_info->name); 846 xfree (font_info->name);
908 font_info->name = NULL; 847 font_info->name = NULL;
909 } 848 }
@@ -994,7 +933,6 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
994{ 933{
995 static unsigned char cbuf[1024]; 934 static unsigned char cbuf[1024];
996 unsigned char *c = cbuf; 935 unsigned char *c = cbuf;
997#ifdef NS_IMPL_GNUSTEP
998#if GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION > 22 936#if GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION > 22
999 static CGFloat advances[1024]; 937 static CGFloat advances[1024];
1000 CGFloat *adv = advances; 938 CGFloat *adv = advances;
@@ -1002,10 +940,6 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1002 static float advances[1024]; 940 static float advances[1024];
1003 float *adv = advances; 941 float *adv = advances;
1004#endif 942#endif
1005#else
1006 static CGSize advances[1024];
1007 CGSize *adv = advances;
1008#endif
1009 struct face *face; 943 struct face *face;
1010 NSRect r; 944 NSRect r;
1011 struct nsfont_info *font; 945 struct nsfont_info *font;
@@ -1073,11 +1007,7 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1073 else 1007 else
1074 { 1008 {
1075 cwidth = LGLYPH_WADJUST (glyph); 1009 cwidth = LGLYPH_WADJUST (glyph);
1076#ifdef NS_IMPL_GNUSTEP
1077 *(adv-1) += LGLYPH_XOFF (glyph); 1010 *(adv-1) += LGLYPH_XOFF (glyph);
1078#else
1079 (*(adv-1)).width += LGLYPH_XOFF (glyph);
1080#endif
1081 } 1011 }
1082 } 1012 }
1083 } 1013 }
@@ -1088,12 +1018,8 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1088 cwidth = font->metrics[hi][lo].width; 1018 cwidth = font->metrics[hi][lo].width;
1089 } 1019 }
1090 twidth += cwidth; 1020 twidth += cwidth;
1091#ifdef NS_IMPL_GNUSTEP
1092 *adv++ = cwidth; 1021 *adv++ = cwidth;
1093 c += CHAR_STRING (*t, c); /* This converts the char to UTF-8. */ 1022 c += CHAR_STRING (*t, c); /* This converts the char to UTF-8. */
1094#else
1095 (*adv++).width = cwidth;
1096#endif
1097 } 1023 }
1098 len = adv - advances; 1024 len = adv - advances;
1099 r.size.width = twidth; 1025 r.size.width = twidth;
@@ -1192,61 +1118,6 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1192 DPSgrestore (context); 1118 DPSgrestore (context);
1193 } 1119 }
1194 1120
1195#else /* NS_IMPL_COCOA */
1196 {
1197 CGContextRef gcontext =
1198 [[NSGraphicsContext currentContext] graphicsPort];
1199 static CGAffineTransform fliptf;
1200 static BOOL firstTime = YES;
1201
1202 if (firstTime)
1203 {
1204 firstTime = NO;
1205 fliptf = CGAffineTransformMakeScale (1.0, -1.0);
1206 }
1207
1208 CGContextSaveGState (gcontext);
1209
1210 // Used to be Fix2X (kATSItalicQDSkew), but Fix2X is deprecated
1211 // and kATSItalicQDSkew is 0.25.
1212 fliptf.c = font->synthItal ? 0.25 : 0.0;
1213
1214 CGContextSetFont (gcontext, font->cgfont);
1215 CGContextSetFontSize (gcontext, font->size);
1216 if (NILP (ns_antialias_text) || font->size <= ns_antialias_threshold)
1217 CGContextSetShouldAntialias (gcontext, 0);
1218 else
1219 CGContextSetShouldAntialias (gcontext, 1);
1220
1221 CGContextSetTextMatrix (gcontext, fliptf);
1222
1223 if (bgCol != nil)
1224 {
1225 /* foreground drawing; erase first to avoid overstrike */
1226 [bgCol set];
1227 CGContextSetTextDrawingMode (gcontext, kCGTextFillStroke);
1228 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
1229 CGContextShowGlyphsWithAdvances (gcontext, s->char2b, advances, len);
1230 CGContextSetTextDrawingMode (gcontext, kCGTextFill);
1231 }
1232
1233 [col set];
1234
1235 CGContextSetTextPosition (gcontext, r.origin.x, r.origin.y);
1236 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + from,
1237 advances, len);
1238
1239 if (face->overstrike)
1240 {
1241 CGContextSetTextPosition (gcontext, r.origin.x+0.5, r.origin.y);
1242 CGContextShowGlyphsWithAdvances (gcontext, s->char2b + from,
1243 advances, len);
1244 }
1245
1246 CGContextRestoreGState (gcontext);
1247 }
1248#endif /* NS_IMPL_COCOA */
1249
1250 unblock_input (); 1121 unblock_input ();
1251 return to-from; 1122 return to-from;
1252} 1123}
@@ -1264,10 +1135,6 @@ nsfont_draw (struct glyph_string *s, int from, int to, int x, int y,
1264static void 1135static void
1265ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block) 1136ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1266{ 1137{
1267#ifdef NS_IMPL_COCOA
1268 static EmacsGlyphStorage *glyphStorage;
1269 static char firstTime = 1;
1270#endif
1271 unichar *unichars = xmalloc (0x101 * sizeof (unichar)); 1138 unichar *unichars = xmalloc (0x101 * sizeof (unichar));
1272 unsigned int i, g, idx; 1139 unsigned int i, g, idx;
1273 unsigned short *glyphs; 1140 unsigned short *glyphs;
@@ -1278,14 +1145,6 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1278 1145
1279 block_input (); 1146 block_input ();
1280 1147
1281#ifdef NS_IMPL_COCOA
1282 if (firstTime)
1283 {
1284 firstTime = 0;
1285 glyphStorage = [[EmacsGlyphStorage alloc] initWithCapacity: 0x100];
1286 }
1287#endif
1288
1289 font_info->glyphs[block] = xmalloc (0x100 * sizeof (unsigned short)); 1148 font_info->glyphs[block] = xmalloc (0x100 * sizeof (unsigned short));
1290 if (!unichars || !(font_info->glyphs[block])) 1149 if (!unichars || !(font_info->glyphs[block]))
1291 emacs_abort (); 1150 emacs_abort ();
@@ -1299,38 +1158,16 @@ ns_uni_to_glyphs (struct nsfont_info *font_info, unsigned char block)
1299 unichars[0x100] = 0; 1158 unichars[0x100] = 0;
1300 1159
1301 { 1160 {
1302#ifdef NS_IMPL_COCOA
1303 NSString *allChars = [[NSString alloc]
1304 initWithCharactersNoCopy: unichars
1305 length: 0x100
1306 freeWhenDone: NO];
1307 NSGlyphGenerator *glyphGenerator = [NSGlyphGenerator sharedGlyphGenerator];
1308 /* NSCharacterSet *coveredChars = [nsfont coveredCharacterSet]; */
1309 unsigned int numGlyphs = [font_info->nsfont numberOfGlyphs];
1310 NSUInteger gInd = 0, cInd = 0;
1311
1312 [glyphStorage setString: allChars font: font_info->nsfont];
1313 [glyphGenerator generateGlyphsForGlyphStorage: glyphStorage
1314 desiredNumberOfCharacters: glyphStorage->maxChar
1315 glyphIndex: &gInd characterIndex: &cInd];
1316#endif
1317 glyphs = font_info->glyphs[block]; 1161 glyphs = font_info->glyphs[block];
1318 for (i = 0; i < 0x100; i++, glyphs++) 1162 for (i = 0; i < 0x100; i++, glyphs++)
1319 { 1163 {
1320#ifdef NS_IMPL_GNUSTEP
1321 g = unichars[i]; 1164 g = unichars[i];
1322#else
1323 g = glyphStorage->cglyphs[i]; 1165 g = glyphStorage->cglyphs[i];
1324 /* TODO: is this a good check? Maybe need to use coveredChars. */ 1166 /* TODO: is this a good check? Maybe need to use coveredChars. */
1325 if (g > numGlyphs || g == NSNullGlyph) 1167 if (g > numGlyphs || g == NSNullGlyph)
1326 g = INVALID_GLYPH; /* Hopefully unused... */ 1168 g = INVALID_GLYPH; /* Hopefully unused... */
1327#endif
1328 *glyphs = g; 1169 *glyphs = g;
1329 } 1170 }
1330
1331#ifdef NS_IMPL_COCOA
1332 [allChars release];
1333#endif
1334 } 1171 }
1335 1172
1336 unblock_input (); 1173 unblock_input ();
@@ -1352,19 +1189,12 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
1352 fprintf (stderr, "%p\tComputing metrics for glyphs in block %d\n", 1189 fprintf (stderr, "%p\tComputing metrics for glyphs in block %d\n",
1353 font_info, block); 1190 font_info, block);
1354 1191
1355#ifdef NS_IMPL_GNUSTEP
1356 /* not implemented yet (as of startup 0.18), so punt */ 1192 /* not implemented yet (as of startup 0.18), so punt */
1357 if (numGlyphs == 0) 1193 if (numGlyphs == 0)
1358 numGlyphs = 0x10000; 1194 numGlyphs = 0x10000;
1359#endif
1360 1195
1361 block_input (); 1196 block_input ();
1362#ifdef NS_IMPL_COCOA
1363 sfont = [font_info->nsfont screenFontWithRenderingMode:
1364 NSFontAntialiasedIntegerAdvancementsRenderingMode];
1365#else
1366 sfont = [font_info->nsfont screenFont]; 1197 sfont = [font_info->nsfont screenFont];
1367#endif
1368 1198
1369 font_info->metrics[block] = xzalloc (0x100 * sizeof (struct font_metrics)); 1199 font_info->metrics[block] = xzalloc (0x100 * sizeof (struct font_metrics));
1370 if (!(font_info->metrics[block])) 1200 if (!(font_info->metrics[block]))
@@ -1397,76 +1227,6 @@ ns_glyph_metrics (struct nsfont_info *font_info, unsigned char block)
1397} 1227}
1398 1228
1399 1229
1400#ifdef NS_IMPL_COCOA
1401/* Helper for font glyph setup. */
1402@implementation EmacsGlyphStorage
1403
1404- init
1405{
1406 return [self initWithCapacity: 1024];
1407}
1408
1409- initWithCapacity: (unsigned long) c
1410{
1411 self = [super init];
1412 maxChar = 0;
1413 maxGlyph = 0;
1414 dict = [NSMutableDictionary new];
1415 cglyphs = xmalloc (c * sizeof (CGGlyph));
1416 return self;
1417}
1418
1419- (void) dealloc
1420{
1421 if (attrStr != nil)
1422 [attrStr release];
1423 [dict release];
1424 xfree (cglyphs);
1425 [super dealloc];
1426}
1427
1428- (void) setString: (NSString *)str font: (NSFont *)font
1429{
1430 [dict setObject: font forKey: NSFontAttributeName];
1431 if (attrStr != nil)
1432 [attrStr release];
1433 attrStr = [[NSAttributedString alloc] initWithString: str attributes: dict];
1434 maxChar = [str length];
1435 maxGlyph = 0;
1436}
1437
1438/* NSGlyphStorage protocol */
1439- (NSUInteger)layoutOptions
1440{
1441 return 0;
1442}
1443
1444- (NSAttributedString *)attributedString
1445{
1446 return attrStr;
1447}
1448
1449- (void)insertGlyphs: (const NSGlyph *)glyphs length: (NSUInteger)length
1450 forStartingGlyphAtIndex: (NSUInteger)glyphIndex
1451 characterIndex: (NSUInteger)charIndex
1452{
1453 len = glyphIndex+length;
1454 for (i =glyphIndex; i<len; i++)
1455 cglyphs[i] = glyphs[i-glyphIndex];
1456 if (len > maxGlyph)
1457 maxGlyph = len;
1458}
1459
1460- (void)setIntAttribute: (NSInteger)attributeTag value: (NSInteger)val
1461 forGlyphAtIndex: (NSUInteger)glyphIndex
1462{
1463 return;
1464}
1465
1466@end
1467#endif /* NS_IMPL_COCOA */
1468
1469
1470/* Debugging */ 1230/* Debugging */
1471void 1231void
1472ns_dump_glyphstring (struct glyph_string *s) 1232ns_dump_glyphstring (struct glyph_string *s)
diff --git a/src/nsimage.m b/src/nsimage.m
index 966e7044f12..da6f01cf6a3 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -36,6 +36,14 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
36#include "coding.h" 36#include "coding.h"
37 37
38 38
39#if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MAX_ALLOWED < 1070
40# define COLORSPACE_NAME NSCalibratedRGBColorSpace
41#else
42# define COLORSPACE_NAME \
43 ((ns_use_srgb_colorspace && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7) \
44 ? NSDeviceRGBColorSpace : NSCalibratedRGBColorSpace)
45#endif
46
39 47
40/* ========================================================================== 48/* ==========================================================================
41 49
@@ -295,7 +303,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
295 pixelsWide: w pixelsHigh: h 303 pixelsWide: w pixelsHigh: h
296 bitsPerSample: 8 samplesPerPixel: 4 304 bitsPerSample: 8 samplesPerPixel: 4
297 hasAlpha: YES isPlanar: YES 305 hasAlpha: YES isPlanar: YES
298 colorSpaceName: NSCalibratedRGBColorSpace 306 colorSpaceName: COLORSPACE_NAME
299 bytesPerRow: w bitsPerPixel: 0]; 307 bytesPerRow: w bitsPerPixel: 0];
300 308
301 [bmRep getBitmapDataPlanes: planes]; 309 [bmRep getBitmapDataPlanes: planes];
@@ -415,7 +423,7 @@ ns_set_alpha (void *img, int x, int y, unsigned char a)
415 /* keep things simple for now */ 423 /* keep things simple for now */
416 bitsPerSample: 8 samplesPerPixel: 4 /*RGB+A*/ 424 bitsPerSample: 8 samplesPerPixel: 4 /*RGB+A*/
417 hasAlpha: YES isPlanar: YES 425 hasAlpha: YES isPlanar: YES
418 colorSpaceName: NSCalibratedRGBColorSpace 426 colorSpaceName: COLORSPACE_NAME
419 bytesPerRow: width bitsPerPixel: 0]; 427 bytesPerRow: width bitsPerPixel: 0];
420 428
421 [bmRep getBitmapDataPlanes: pixmapData]; 429 [bmRep getBitmapDataPlanes: pixmapData];
diff --git a/src/nsterm.h b/src/nsterm.h
index b56bcad4dc1..f292993d8f7 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -718,22 +718,6 @@ typedef id instancetype;
718 718
719 ========================================================================== */ 719 ========================================================================== */
720 720
721#ifdef NS_IMPL_COCOA
722/* rendering util */
723@interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
724{
725@public
726 NSAttributedString *attrStr;
727 NSMutableDictionary *dict;
728 CGGlyph *cglyphs;
729 unsigned long maxChar, maxGlyph;
730 long i, len;
731}
732- (instancetype)initWithCapacity: (unsigned long) c;
733- (void) setString: (NSString *)str font: (NSFont *)font;
734@end
735#endif /* NS_IMPL_COCOA */
736
737extern NSArray *ns_send_types, *ns_return_types; 721extern NSArray *ns_send_types, *ns_return_types;
738extern NSString *ns_app_name; 722extern NSString *ns_app_name;
739extern EmacsMenu *svcsMenu; 723extern EmacsMenu *svcsMenu;
@@ -811,6 +795,7 @@ struct ns_color_table
811#define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101) 795#define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
812#define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101) 796#define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
813 797
798#ifdef NS_IMPL_GNUSTEP
814/* this extends font backend font */ 799/* this extends font backend font */
815struct nsfont_info 800struct nsfont_info
816{ 801{
@@ -827,14 +812,8 @@ struct nsfont_info
827 float size; 812 float size;
828#ifdef __OBJC__ 813#ifdef __OBJC__
829 NSFont *nsfont; 814 NSFont *nsfont;
830#if defined (NS_IMPL_COCOA)
831 CGFontRef cgfont;
832#else /* GNUstep */
833 void *cgfont;
834#endif
835#else /* ! OBJC */ 815#else /* ! OBJC */
836 void *nsfont; 816 void *nsfont;
837 void *cgfont;
838#endif 817#endif
839 char bold, ital; /* convenience flags */ 818 char bold, ital; /* convenience flags */
840 char synthItal; 819 char synthItal;
@@ -844,7 +823,7 @@ struct nsfont_info
844 unsigned short **glyphs; /* map Unicode index to glyph */ 823 unsigned short **glyphs; /* map Unicode index to glyph */
845 struct font_metrics **metrics; 824 struct font_metrics **metrics;
846}; 825};
847 826#endif
848 827
849/* Initialized in ns_initialize_display_info (). */ 828/* Initialized in ns_initialize_display_info (). */
850struct ns_display_info 829struct ns_display_info
@@ -1107,7 +1086,7 @@ extern void ns_term_shutdown (int sig);
1107#define NS_DUMPGLYPH_MOUSEFACE 3 1086#define NS_DUMPGLYPH_MOUSEFACE 3
1108 1087
1109 1088
1110 1089#ifdef NS_IMPL_GNUSTEP
1111/* In nsfont, called from fontset.c */ 1090/* In nsfont, called from fontset.c */
1112extern void nsfont_make_fontset_for_font (Lisp_Object name, 1091extern void nsfont_make_fontset_for_font (Lisp_Object name,
1113 Lisp_Object font_object); 1092 Lisp_Object font_object);
@@ -1115,6 +1094,7 @@ extern void nsfont_make_fontset_for_font (Lisp_Object name,
1115/* In nsfont, for debugging */ 1094/* In nsfont, for debugging */
1116struct glyph_string; 1095struct glyph_string;
1117void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE; 1096void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE;
1097#endif
1118 1098
1119/* Implemented in nsterm, published in or needed from nsfns. */ 1099/* Implemented in nsterm, published in or needed from nsfns. */
1120extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern, 1100extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
@@ -1274,6 +1254,19 @@ extern char gnustep_base_version[]; /* version tracking */
1274 ? (min) : (((x)>(max)) ? (max) : (x))) 1254 ? (min) : (((x)>(max)) ? (max) : (x)))
1275#define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX)) 1255#define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1276 1256
1257
1258#ifdef NS_IMPL_COCOA
1259/* Add some required AppKit version numbers if they're not defined. */
1260#ifndef NSAppKitVersionNumber10_7
1261#define NSAppKitVersionNumber10_7 1138
1262#endif
1263
1264#ifndef NSAppKitVersionNumber10_10
1265#define NSAppKitVersionNumber10_10 1343
1266#endif
1267#endif /* NS_IMPL_COCOA */
1268
1269
1277/* macOS 10.7 introduces some new constants. */ 1270/* macOS 10.7 introduces some new constants. */
1278#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7) 1271#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
1279#define NSFullScreenWindowMask (1 << 14) 1272#define NSFullScreenWindowMask (1 << 14)
diff --git a/src/nsterm.m b/src/nsterm.m
index 5e5d09f058b..fdcd677d144 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -140,14 +140,9 @@ char const * nstrace_fullscreen_type_name (int fs_type)
140+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green 140+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
141 blue:(CGFloat)blue alpha:(CGFloat)alpha 141 blue:(CGFloat)blue alpha:(CGFloat)alpha
142{ 142{
143#if defined (NS_IMPL_COCOA) \ 143#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
144 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
145 if (ns_use_srgb_colorspace 144 if (ns_use_srgb_colorspace
146#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 145 && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
147 && [NSColor respondsToSelector:
148 @selector(colorWithSRGBRed:green:blue:alpha:)]
149#endif
150 )
151 return [NSColor colorWithSRGBRed: red 146 return [NSColor colorWithSRGBRed: red
152 green: green 147 green: green
153 blue: blue 148 blue: blue
@@ -161,28 +156,12 @@ char const * nstrace_fullscreen_type_name (int fs_type)
161 156
162- (NSColor *)colorUsingDefaultColorSpace 157- (NSColor *)colorUsingDefaultColorSpace
163{ 158{
164 /* FIXME: We're checking for colorWithSRGBRed here so this will only 159#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
165 work in the same place as in the method above. It should really 160 if (ns_use_srgb_colorspace
166 be a check whether we're on macOS 10.7 or above. */ 161 && NSAppKitVersionNumber >= NSAppKitVersionNumber10_7)
167#if defined (NS_IMPL_COCOA) \ 162 return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]];
168 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
169#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
170 if ([NSColor respondsToSelector:
171 @selector(colorWithSRGBRed:green:blue:alpha:)])
172#endif
173 {
174 if (ns_use_srgb_colorspace)
175 return [self colorUsingColorSpace: [NSColorSpace sRGBColorSpace]];
176 else
177 return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]];
178 }
179#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
180 else
181#endif
182#endif /* NS_IMPL_COCOA && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */
183#if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MIN_REQUIRED < 1070
184 return [self colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
185#endif 163#endif
164 return [self colorUsingColorSpace: [NSColorSpace deviceRGBColorSpace]];
186} 165}
187 166
188@end 167@end
@@ -2209,10 +2188,6 @@ ns_set_appearance (struct frame *f, Lisp_Object new_value, Lisp_Object old_value
2209 2188
2210 NSTRACE ("ns_set_appearance"); 2189 NSTRACE ("ns_set_appearance");
2211 2190
2212#ifndef NSAppKitVersionNumber10_10
2213#define NSAppKitVersionNumber10_10 1343
2214#endif
2215
2216 if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10) 2191 if (NSAppKitVersionNumber < NSAppKitVersionNumber10_10)
2217 return; 2192 return;
2218 2193
@@ -3053,6 +3028,40 @@ ns_scroll_run (struct window *w, struct run *run)
3053 3028
3054 3029
3055static void 3030static void
3031ns_clear_under_internal_border (struct frame *f)
3032{
3033 NSTRACE ("ns_clear_under_internal_border");
3034
3035 if (FRAME_INTERNAL_BORDER_WIDTH (f) > 0)
3036 {
3037 int border_width = FRAME_INTERNAL_BORDER_WIDTH (f);
3038 NSView *view = FRAME_NS_VIEW (f);
3039 NSRect edge_rect, frame_rect = [view bounds];
3040 NSRectEdge edge[] = {NSMinXEdge, NSMinYEdge, NSMaxXEdge, NSMaxYEdge};
3041
3042 int face_id =
3043 !NILP (Vface_remapping_alist)
3044 ? lookup_basic_face (NULL, f, INTERNAL_BORDER_FACE_ID)
3045 : INTERNAL_BORDER_FACE_ID;
3046 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
3047
3048 if (!face)
3049 face = FRAME_DEFAULT_FACE (f);
3050
3051 ns_focus (f, &frame_rect, 1);
3052 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set];
3053 for (int i = 0; i < 4 ; i++)
3054 {
3055 NSDivideRect (frame_rect, &edge_rect, &frame_rect, border_width, edge[i]);
3056
3057 NSRectFill (edge_rect);
3058 }
3059 ns_unfocus (f);
3060 }
3061}
3062
3063
3064static void
3056ns_after_update_window_line (struct window *w, struct glyph_row *desired_row) 3065ns_after_update_window_line (struct window *w, struct glyph_row *desired_row)
3057/* -------------------------------------------------------------------------- 3066/* --------------------------------------------------------------------------
3058 External (RIF): preparatory to fringe update after text was updated 3067 External (RIF): preparatory to fringe update after text was updated
@@ -3080,12 +3089,32 @@ ns_after_update_window_line (struct window *w, struct glyph_row *desired_row)
3080 height > 0)) 3089 height > 0))
3081 { 3090 {
3082 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y)); 3091 int y = WINDOW_TO_FRAME_PIXEL_Y (w, max (0, desired_row->y));
3092 int face_id =
3093 !NILP (Vface_remapping_alist)
3094 ? lookup_basic_face (NULL, f, INTERNAL_BORDER_FACE_ID)
3095 : INTERNAL_BORDER_FACE_ID;
3096 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
3083 3097
3084 block_input (); 3098 block_input ();
3085 ns_clear_frame_area (f, 0, y, width, height); 3099 if (face)
3086 ns_clear_frame_area (f, 3100 {
3087 FRAME_PIXEL_WIDTH (f) - width, 3101 NSRect r = NSMakeRect (0, y, FRAME_PIXEL_WIDTH (f), height);
3088 y, width, height); 3102 ns_focus (f, &r, 1);
3103
3104 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), f) set];
3105 NSRectFill (NSMakeRect (0, y, width, height));
3106 NSRectFill (NSMakeRect (FRAME_PIXEL_WIDTH (f) - width,
3107 y, width, height));
3108
3109 ns_unfocus (f);
3110 }
3111 else
3112 {
3113 ns_clear_frame_area (f, 0, y, width, height);
3114 ns_clear_frame_area (f,
3115 FRAME_PIXEL_WIDTH (f) - width,
3116 y, width, height);
3117 }
3089 unblock_input (); 3118 unblock_input ();
3090 } 3119 }
3091} 3120}
@@ -3140,10 +3169,12 @@ ns_compute_glyph_string_overhangs (struct glyph_string *s)
3140 else 3169 else
3141 { 3170 {
3142 s->left_overhang = 0; 3171 s->left_overhang = 0;
3172#ifdef NS_IMPL_GNUSTEP
3143 if (EQ (font->driver->type, Qns)) 3173 if (EQ (font->driver->type, Qns))
3144 s->right_overhang = ((struct nsfont_info *)font)->ital ? 3174 s->right_overhang = ((struct nsfont_info *)font)->ital ?
3145 FONT_HEIGHT (font) * 0.2 : 0; 3175 FONT_HEIGHT (font) * 0.2 : 0;
3146 else 3176 else
3177#endif
3147 s->right_overhang = 0; 3178 s->right_overhang = 0;
3148 } 3179 }
3149} 3180}
@@ -5301,7 +5332,7 @@ static struct redisplay_interface ns_redisplay_interface =
5301 ns_draw_glyph_string, 5332 ns_draw_glyph_string,
5302 ns_define_frame_cursor, 5333 ns_define_frame_cursor,
5303 ns_clear_frame_area, 5334 ns_clear_frame_area,
5304 0, /* clear_under_internal_border */ 5335 ns_clear_under_internal_border, /* clear_under_internal_border */
5305 ns_draw_window_cursor, 5336 ns_draw_window_cursor,
5306 ns_draw_vertical_window_border, 5337 ns_draw_vertical_window_border,
5307 ns_draw_window_divider, 5338 ns_draw_window_divider,
diff --git a/src/process.c b/src/process.c
index 53f4a1d8530..50c425077a9 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1205,6 +1205,16 @@ not the name of the pty that Emacs uses to talk with that terminal. */)
1205 return XPROCESS (process)->tty_name; 1205 return XPROCESS (process)->tty_name;
1206} 1206}
1207 1207
1208static void
1209update_process_mark (struct Lisp_Process *p)
1210{
1211 Lisp_Object buffer = p->buffer;
1212 if (BUFFERP (buffer))
1213 set_marker_both (p->mark, buffer,
1214 BUF_ZV (XBUFFER (buffer)),
1215 BUF_ZV_BYTE (XBUFFER (buffer)));
1216}
1217
1208DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer, 1218DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer,
1209 2, 2, 0, 1219 2, 2, 0,
1210 doc: /* Set buffer associated with PROCESS to BUFFER (a buffer, or nil). 1220 doc: /* Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
@@ -1217,7 +1227,11 @@ Return BUFFER. */)
1217 if (!NILP (buffer)) 1227 if (!NILP (buffer))
1218 CHECK_BUFFER (buffer); 1228 CHECK_BUFFER (buffer);
1219 p = XPROCESS (process); 1229 p = XPROCESS (process);
1220 pset_buffer (p, buffer); 1230 if (!EQ (p->buffer, buffer))
1231 {
1232 pset_buffer (p, buffer);
1233 update_process_mark (p);
1234 }
1221 if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p)) 1235 if (NETCONN1_P (p) || SERIALCONN1_P (p) || PIPECONN1_P (p))
1222 pset_childp (p, Fplist_put (p->childp, QCbuffer, buffer)); 1236 pset_childp (p, Fplist_put (p->childp, QCbuffer, buffer));
1223 setup_process_coding_systems (process); 1237 setup_process_coding_systems (process);
@@ -1637,6 +1651,7 @@ DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0,
1637 return Fmapcar (Qcdr, Vprocess_alist); 1651 return Fmapcar (Qcdr, Vprocess_alist);
1638} 1652}
1639 1653
1654
1640/* Starting asynchronous inferior processes. */ 1655/* Starting asynchronous inferior processes. */
1641 1656
1642DEFUN ("make-process", Fmake_process, Smake_process, 0, MANY, 0, 1657DEFUN ("make-process", Fmake_process, Smake_process, 0, MANY, 0,
@@ -1805,10 +1820,7 @@ usage: (make-process &rest ARGS) */)
1805 : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2); 1820 : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2);
1806 1821
1807 /* Make the process marker point into the process buffer (if any). */ 1822 /* Make the process marker point into the process buffer (if any). */
1808 if (BUFFERP (buffer)) 1823 update_process_mark (XPROCESS (proc));
1809 set_marker_both (XPROCESS (proc)->mark, buffer,
1810 BUF_ZV (XBUFFER (buffer)),
1811 BUF_ZV_BYTE (XBUFFER (buffer)));
1812 1824
1813 USE_SAFE_ALLOCA; 1825 USE_SAFE_ALLOCA;
1814 1826
@@ -2453,10 +2465,7 @@ usage: (make-pipe-process &rest ARGS) */)
2453 : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2); 2465 : EQ (Vprocess_adaptive_read_buffering, Qt) ? 1 : 2);
2454 2466
2455 /* Make the process marker point into the process buffer (if any). */ 2467 /* Make the process marker point into the process buffer (if any). */
2456 if (BUFFERP (buffer)) 2468 update_process_mark (p);
2457 set_marker_both (p->mark, buffer,
2458 BUF_ZV (XBUFFER (buffer)),
2459 BUF_ZV_BYTE (XBUFFER (buffer)));
2460 2469
2461 { 2470 {
2462 /* Setup coding systems for communicating with the network stream. */ 2471 /* Setup coding systems for communicating with the network stream. */
@@ -3182,12 +3191,7 @@ usage: (make-serial-process &rest ARGS) */)
3182 if (!EQ (p->command, Qt)) 3191 if (!EQ (p->command, Qt))
3183 add_process_read_fd (fd); 3192 add_process_read_fd (fd);
3184 3193
3185 if (BUFFERP (buffer)) 3194 update_process_mark (p);
3186 {
3187 set_marker_both (p->mark, buffer,
3188 BUF_ZV (XBUFFER (buffer)),
3189 BUF_ZV_BYTE (XBUFFER (buffer)));
3190 }
3191 3195
3192 tem = Fplist_get (contact, QCcoding); 3196 tem = Fplist_get (contact, QCcoding);
3193 3197
@@ -3664,10 +3668,7 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos,
3664 pset_status (p, Qlisten); 3668 pset_status (p, Qlisten);
3665 3669
3666 /* Make the process marker point into the process buffer (if any). */ 3670 /* Make the process marker point into the process buffer (if any). */
3667 if (BUFFERP (p->buffer)) 3671 update_process_mark (p);
3668 set_marker_both (p->mark, p->buffer,
3669 BUF_ZV (XBUFFER (p->buffer)),
3670 BUF_ZV_BYTE (XBUFFER (p->buffer)));
3671 3672
3672 if (p->is_non_blocking_client) 3673 if (p->is_non_blocking_client)
3673 { 3674 {
diff --git a/src/syntax.c b/src/syntax.c
index e6af8a377bb..066972e6d88 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -2354,6 +2354,13 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
2354 /* We have encountered a nested comment of the same style 2354 /* We have encountered a nested comment of the same style
2355 as the comment sequence which began this comment section. */ 2355 as the comment sequence which began this comment section. */
2356 nesting++; 2356 nesting++;
2357 if (comment_end_can_be_escaped
2358 && (code == Sescape || code == Scharquote))
2359 {
2360 inc_both (&from, &from_byte);
2361 UPDATE_SYNTAX_TABLE_FORWARD (from);
2362 if (from == stop) continue; /* Failure */
2363 }
2357 inc_both (&from, &from_byte); 2364 inc_both (&from, &from_byte);
2358 UPDATE_SYNTAX_TABLE_FORWARD (from); 2365 UPDATE_SYNTAX_TABLE_FORWARD (from);
2359 2366
diff --git a/src/xdisp.c b/src/xdisp.c
index ac5307f4acc..3d40878be65 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -11809,7 +11809,20 @@ resize_mini_window (struct window *w, bool exact_p)
11809 height = (max_height / unit) * unit; 11809 height = (max_height / unit) * unit;
11810 init_iterator (&it, w, ZV, ZV_BYTE, NULL, DEFAULT_FACE_ID); 11810 init_iterator (&it, w, ZV, ZV_BYTE, NULL, DEFAULT_FACE_ID);
11811 move_it_vertically_backward (&it, height - unit); 11811 move_it_vertically_backward (&it, height - unit);
11812 /* The following move is usually a no-op when the stuff
11813 displayed in the mini-window comes entirely from buffer
11814 text, but it is needed when some of it comes from overlay
11815 strings, especially when there's an after-string at ZV.
11816 This happens with some completion packages, like
11817 icomplete, ido-vertical, etc. With those packages, if we
11818 don't force w->start to be at the beginning of a screen
11819 line, important parts of the stuff in the mini-window,
11820 such as user prompt, will be hidden from view. */
11821 move_it_by_lines (&it, 0);
11812 start = it.current.pos; 11822 start = it.current.pos;
11823 /* Prevent redisplay_window from recentering, and thus from
11824 overriding the window-start point we computed here. */
11825 w->start_at_line_beg = false;
11813 } 11826 }
11814 else 11827 else
11815 SET_TEXT_POS (start, BEGV, BEGV_BYTE); 11828 SET_TEXT_POS (start, BEGV, BEGV_BYTE);