2011-12-04 9 views
12

que tienen la siguiente función para imprimir la línea en cuestión es el búfer * scratch *,imprimir sólo las propiedades de texto de texto de descarte

(defun print-line() 
    (print (thing-at-point 'line) (get-buffer "*scratch*"))) 

pero las copias después de la información fontified como esto

#(" OFFICE 
" 0 2 (fontified t org ... 

Cómo descartar la impresión de la información de fuente.

Respuesta

8

Necesitaba algo similar para eredis al manipular cadenas de una tabla de organización. Puede usar `set-text-properties' para deshacerse de ellos cuando muestre la cadena.

(defun strip-text-properties(txt) 
    (set-text-properties 0 (length txt) nil txt) 
     txt) 

(defun print-line() 
(print (strip-text-properties 
     (thing-at-point 'line)) 
    (get-buffer "*scratch*"))) 
1

He intentado algunas cosas pero es extraño, realmente no entiendo cómo funcionan las propiedades del texto.

Por ejemplo:

(type-of (thing-at-point 'line)) => string 

Como usted ha dicho, si uno trata de imprimirlo, las propiedades se imprimen también, pero si uno trata de insertarlo:

(insert (format "%s" (thing-at-point 'line))) 

Sólo el la cadena está impresa, no las propiedades.

Por lo tanto, me parece que esas propiedades son simplemente unidos a la cadena, pero se puede manipular la cadena como de costumbre:

(lenght (thing-at-point 'line)) 
(substring (thing-at-point 'line) 0 2) 

Sin embargo, si lo que quieres es la línea, y sólo la línea Puede utilizar buffer-substring-no-properties:

(defun print-line()  
    (print (buffer-substring-no-properties (point-at-bol) (point-at-eol)))) 
+1

Incluso la cadena de almacenamiento intermedio imprime los mensajes de fuente, las propiedades de buffer-substring-no-properties sin mensajes de fuente. –

+0

@Talespin_Kit: Oh, tienes toda la razón. – Daimrod

16

Para ampliar mención buffer-substring-no-properties de Daimrod ...

MxaproposRET RETno-properties

buffer-substring-no-properties 
    Function: Return the characters of part of the buffer, without the 
      text properties. 
field-string-no-properties 
    Function: Return the contents of the field around POS, without text 
      properties. 
insert-buffer-substring-no-properties 
    Function: Insert before point a substring of BUFFER, without text 
      properties. 
match-string-no-properties 
    Function: Return string of text matched by last search, without text 
      properties. 
minibuffer-contents-no-properties 
    Function: Return the user input in a minibuffer as a string, without 
      text-properties. 
substring-no-properties 
    Function: Return a substring of STRING, without text properties. 

Usted puede leer acerca de las propiedades del texto en el manual:

M-: (info "(elisp) Propiedades del texto") RET

+1

Woa No he notado 'substring-no-properties', pero con eso se puede hacer' (defun print-line() (let ((línea (cosa-en-línea))) (substring-no -properties línea 0 (línea de longitud)))) '. – Daimrod

+0

@Daimrod Los argumentos de 'substring-no-properties' son opcionales. – ceving

Cuestiones relacionadas