emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] feature/byte-switch 3795646: update branch


From: Vibhav Pant
Subject: [Emacs-diffs] feature/byte-switch 3795646: update branch
Date: Mon, 16 Jan 2017 14:24:51 +0000 (UTC)

branch: feature/byte-switch
commit 37956463d67795819fe7d8fe02d6249388364783
Merge: 309b464 fd6b829
Author: Vibhav Pant <address@hidden>
Commit: Vibhav Pant <address@hidden>

    update branch
---
 lisp/ffap.el                |   66 +++++++++++++++++++++++--------------------
 lisp/progmodes/cc-engine.el |   26 +++++++++++++----
 src/nsterm.m                |    4 +--
 test/lisp/ffap-tests.el     |   17 +++++++++++
 4 files changed, 74 insertions(+), 39 deletions(-)

diff --git a/lisp/ffap.el b/lisp/ffap.el
index 8144d41..068897b 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -76,6 +76,7 @@
 ;; (setq ffap-machine-p-known 'accept)  ; no pinging
 ;; (setq ffap-url-regexp nil)           ; disable URL features in ffap
 ;; (setq ffap-shell-prompt-regexp nil)  ; disable shell prompt stripping
+;; (setq ffap-gopher-regexp nil)        ; disable gopher bookmark matching
 ;;
 ;; ffap uses `browse-url' (if found, else `w3-fetch') to fetch URL's.
 ;; For a hairier `ffap-url-fetcher', try ffap-url.el (same ftp site).
@@ -1194,43 +1195,46 @@ Sets the variable `ffap-string-at-point-region' to the 
bounds of URL, if any."
           val))))
 
 (defvar ffap-gopher-regexp
-  "^.*\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *\\(.*\\) *$"
-  "Regexp matching a line in a gopher bookmark (maybe indented).
-The two subexpressions are the KEY and VALUE.")
+  "\\<\\(Type\\|Name\\|Path\\|Host\\|Port\\) *= *"
+  "Regexp matching a key in a gopher bookmark.
+Set to nil to disable matching gopher bookmarks.")
+
+(defun ffap--gopher-var-on-line ()
+  "Return (KEY . VALUE) of gopher bookmark on current line."
+  (save-excursion
+    (let ((eol (progn (end-of-line) (skip-chars-backward " ") (point)))
+          (bol (progn (beginning-of-line) (point))))
+     (when (re-search-forward ffap-gopher-regexp eol t)
+       (let ((key (match-string 1))
+             (val (buffer-substring-no-properties (match-end 0) eol)))
+         (cons (intern (downcase key)) val))))))
 
 (defun ffap-gopher-at-point ()
   "If point is inside a gopher bookmark block, return its URL.
 
 Sets the variable `ffap-string-at-point-region' to the bounds of URL, if any."
   ;; `gopher-parse-bookmark' from gopher.el is not so robust
-  (save-excursion
-    (beginning-of-line)
-    (if (looking-at ffap-gopher-regexp)
-       (progn
-         (while (and (looking-at ffap-gopher-regexp) (not (bobp)))
-           (forward-line -1))
-         (or (looking-at ffap-gopher-regexp) (forward-line 1))
-          (setq ffap-string-at-point-region (list (point) (point)))
-         (let ((type "1") path host (port "70"))
-           (while (looking-at ffap-gopher-regexp)
-             (let ((var (intern
-                         (downcase
-                          (buffer-substring (match-beginning 1)
-                                            (match-end 1)))))
-                   (val (buffer-substring (match-beginning 2)
-                                          (match-end 2))))
-               (set var val)
-               (forward-line 1)))
-            (setcdr ffap-string-at-point-region (list (point)))
-           (if (and path (string-match "^ftp:.*@" path))
-               (concat "ftp://";
-                       (substring path 4 (1- (match-end 0)))
-                       (substring path (match-end 0)))
-             (and (= (length type) 1)
-                  host;; (ffap-machine-p host)
-                  (concat "gopher://"; host
-                          (if (equal port "70") "" (concat ":" port))
-                          "/" type path))))))))
+  (when (stringp ffap-gopher-regexp)
+    (save-excursion
+      (let* ((beg (progn (beginning-of-line)
+                         (while (and (not (bobp)) (ffap--gopher-var-on-line))
+                           (forward-line -1))
+                         (point)))
+             (bookmark (cl-loop for keyval = (ffap--gopher-var-on-line)
+                                while keyval collect keyval
+                                do (forward-line 1))))
+        (when bookmark
+          (setq ffap-string-at-point-region (list beg (point)))
+          (let-alist (nconc bookmark '((type . "1") (port . "70")))
+            (if (and .path (string-match "\\`ftp:.*@" .path))
+                (concat "ftp://";
+                        (substring .path 4 (1- (match-end 0)))
+                        (substring .path (match-end 0)))
+              (and (= (length .type) 1)
+                   .host ;; (ffap-machine-p host)
+                   (concat "gopher://"; .host
+                           (if (equal .port "70") "" (concat ":" .port))
+                           "/" .type .path)))))))))
 
 (defvar ffap-ftp-sans-slash-regexp
   (and
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 3077e00..e84c4ce 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2931,11 +2931,23 @@ comment at the start of cc-engine.el for more info."
   ;; o - ('BOD START-POINT) - scan forwards from START-POINT, which is at the
   ;;   top level.
   ;; o - ('IN-LIT nil) - point is inside the literal containing point-min.
-  (let ((cache-pos (c-get-cache-scan-pos here))        ; highest position 
below HERE in cache (or 1)
-       BOD-pos             ; position of 2nd BOD before HERE.
-       strategy            ; 'forward, 'backward, 'BOD, or 'IN-LIT.
-       start-point
-       how-far)                        ; putative scanning distance.
+  (let* ((in-macro-start             ; start of macro containing HERE or nil.
+         (save-excursion
+           (goto-char here)
+           (and (c-beginning-of-macro)
+                (point))))
+        (changed-macro-start
+         (and in-macro-start
+              (not (and c-state-old-cpp-beg
+                        (= in-macro-start c-state-old-cpp-beg)))
+              in-macro-start))
+        (cache-pos (c-get-cache-scan-pos (if changed-macro-start
+                                             (min changed-macro-start here)
+                                           here))) ; highest suitable position 
in cache (or 1)
+        BOD-pos                      ; position of 2nd BOD before HERE.
+        strategy                     ; 'forward, 'backward, 'BOD, or 'IN-LIT.
+        start-point
+        how-far)                       ; putative scanning distance.
     (setq good-pos (or good-pos (c-state-get-min-scan-pos)))
     (cond
      ((< here (c-state-get-min-scan-pos))
@@ -2945,7 +2957,9 @@ comment at the start of cc-engine.el for more info."
            how-far 0))
      ((<= good-pos here)
       (setq strategy 'forward
-           start-point (max good-pos cache-pos)
+           start-point (if changed-macro-start
+                           cache-pos
+                         (max good-pos cache-pos))
            how-far (- here start-point)))
      ((< (- good-pos here) (- here cache-pos)) ; FIXME!!! ; apply some sort of 
weighting.
       (setq strategy 'backward
diff --git a/src/nsterm.m b/src/nsterm.m
index 90664f6..63f1b15 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4039,7 +4039,7 @@ ns_read_socket (struct terminal *terminal, struct 
input_event *hold_quit)
       return i;
     }
 
-  if ([NSThread mainThread])
+  if ([NSThread isMainThread])
     {
       block_input ();
       n_emacs_events_pending = 0;
@@ -4123,7 +4123,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
     }
 
   if (NSApp == nil
-      || ![NSThread mainThread]
+      || ![NSThread isMainThread]
       || (timeout && timeout->tv_sec == 0 && timeout->tv_nsec == 0))
     return pselect (nfds, readfds, writefds, exceptfds, timeout, sigmask);
 
diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el
index 1ba5f86..a3fe350 100644
--- a/test/lisp/ffap-tests.el
+++ b/test/lisp/ffap-tests.el
@@ -49,6 +49,23 @@ index 3d7cebadcf..ad4b70d737 100644
               (should (equal '(1 1) ffap-string-at-point-region)))))
       (and (file-exists-p file) (delete-file file)))))
 
+(ert-deftest ffap-gopher-at-point ()
+  (with-temp-buffer
+    (insert "\
+Type = 1
+Name = foo
+Path = /the/path
+Port = 7070
+Host = example.com\n")
+    (should-not (ffap-gopher-at-point))
+    (goto-char (point-min))
+    (should (equal (ffap-gopher-at-point)
+                   "gopher://example.com:7070/1/the/path";))
+    (should (equal ffap-string-at-point-region
+                   (list (point-min) (point-max))))
+    (let ((ffap-gopher-regexp nil))
+      (should-not (ffap-gopher-at-point)))))
+
 (provide 'ffap-tests)
 
 ;;; ffap-tests.el ends here



reply via email to

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