tags:

views:

58

answers:

2

My problem is I am opening a buffer using (set-buffer (find-tag-noselect (current-word))) and then I try to copy some text out of that buffer. The text that I get back has only the properties (fontified nil). find-tag-noselect automatically opens the buffer found in the TAGS file but it seems it does not run the font lock mode over it. When I manually switch to this buffer after it has been opened and then run the function again when it copies the text it has all the correct text properties attached. So what do I need to do to have this buffer completely initialized so that the correct syntax highlighting will be copied in?

(defvar newline-string "
")

(defun get-initial-indent-regexp-python()
  "Gets the initial amount of spaces for the function we are looking at, does not account for tabs"
  (concat "^" (get-current-indent-string) (concat "[^ #" newline-string "]")))


(defun get-end-of-function-python(spaces-regex)
  "Gets the point at the end of a python block"
  (save-excursion
    (forward-line 1)
    (while (and (not (looking-at spaces-regex)) (equal (forward-line 1) 0)))
    (point)))

(defun get-point-at-end-of-function ()
  "This might be better served checking the major mode."
  (setq extension (file-name-extension (buffer-file-name)))
  (if (equal extension "py")
      (get-end-of-function-python (get-initial-indent-regexp-python))))
(defun inline-function ()
  "Must change to overlays, be able to toggle visibility"
  (interactive)
  (let (text indent-string)
                    ; clean all overlays without attached buffer
    (save-excursion
      (set-buffer (find-tag-noselect (current-word)))
      (setq text (buffer-substring (point) (get-point-at-end-of-function))))

    (setq text (concat newline-string text))
    (save-excursion
      (move-end-of-line nil)
      (let (overlay)
    (setq overlay (make-overlay (point) (+ (point) 1) (current-buffer)))
    (overlay-put overlay 'display text)
    (setq inline-func-overlays (cons overlay inline-func-overlays))))))
A: 

I'm not exactly sure what you're trying to do, but set-buffer does not display the buffer, so its effect ends when the current command terminates. It's generally useful only for temporary buffer switches inside a function and I guess this is the reason it doesn't run font-lock on the buffer. When you manually go to the buffer you're probably using a different function - switch-to-buffer.

Bozhidar Batsov
It does not work. It switches to the buffer and leaves it as the current-buffer, when I run the function again by going back to the original buffer than the text properties are copied. Very strange.
jacob
A: 

Try explicitly calling 'font-lock-fontify-buffer'.

sanityinc
Doesn't help unfortunately.
jacob