-;; Time-stamp: <2016-07-22 18:33:33 kmodi>
+;; Time-stamp: <2016-07-25 17:19:07 kmodi>
 
 (>=e "25.0"
     (setq fast-but-imprecise-scrolling t))

the comment start characters (especially for major modes that have '//' as
comment start characters).

Sets variables `ffap-string-at-point' and `ffap-string-at-point-region'. "
      (let* ((args
              (cdr
               (or (assq (or mode major-mode) ffap-string-at-point-mode-alist)

                      (skip-chars-backward (car args))
                      (skip-chars-forward (nth 1 args) pt)
                      (point))))
             (end (if region-selected
                      (region-end)
                    (save-excursion
                      (skip-chars-forward (car args))
                      (skip-chars-backward (nth 2 args) pt)
                      (point))))
             (beg-new beg))
        ;; (message "ffap-string-at-point dbg: beg = %d end = %d" beg end)
        ;; If the initial characters of the to-be-returned string are the
        ;; current major mode's comment starter characters, *and* are not part
        ;; of a comment, remove those from the returned string (Bug#24057).
        ;; Example comments in `c-mode' (which considers lines beginning with
        ;; "//" as comments):
        ;;  //tmp - This is a comment. It does not contain any path reference.
        ;;  ///tmp - This is a comment. The "/tmp" portion in that is a path.
        ;;  ////tmp - This is a comment. The "//tmp" portion in that is a path.
        (when (and
               ;; Proceed if no region is selected by the user.
               (null region-selected)
               ;; Check if END character is part of a comment.
               (save-excursion
                 (goto-char end)
                 (nth 4 (syntax-ppss))))
          (save-excursion
            ;; Increment BEG till point at BEG is in a comment too.
            ;; (nth 4 (syntax-ppss)) will be nil for comment start characters
            ;; (for example, for the "//" characters in `c-mode' line comments).
            (setq beg (catch 'break
                        (while (< beg-new end)
                          (goto-char beg-new)
                          (if (nth 4 (syntax-ppss)) ; in a comment
                              (throw 'break beg-new)
                            (setq beg-new (1+ beg-new))))
                        end)))) ; Set BEG to END if no throw happens
        ;; (message "ffap-string-at-point dbg: beg = %d beg-new = %d" beg beg-new)
        (setq ffap-string-at-point
              (buffer-substring-no-properties
               (setcar ffap-string-at-point-region beg)
               (setcar (cdr ffap-string-at-point-region) end)))
        ;; (message "ffap-string-at-point dbg: ffap-string-at-point = %S"
        ;;          ffap-string-at-point)
        ffap-string-at-point))
    (advice-add 'ffap-string-at-point :override #'modi/ffap-string-at-point)))

;; Inspired from this emacs.SE question: http://emacs.stackexchange.com/q/4271/115
