2

I'm trying to read a value of variable context from the config file. I use something like this (but have got an error..):

(with-current-buffer
(insert-file-contents "/home/user/liquibase.properties")
(keep-lines "contexts" point-min point-max)
)

The file /home/user/liquibase.properties has the following structure:

logLevel: off
contexts: my_context
...

Give me a direction please. How to read the content of properties-file, filter it and store some value into a variable? To have the same result as after a call:

(setq ctx "my_context")
Drew
  • 75,699
  • 9
  • 109
  • 225
egor7
  • 123
  • 6
  • 1
    Point-min and point-max should be function calls. After that you need to parse the line maybe with regular expression or substring. – John Kitchin Oct 20 '16 at 12:49
  • Thanks, John. I've changed point-min/max to (point-min/max). Now it prints the value to the current buffer. How could I parse it and save into var, instead of printing to the buffer? – egor7 Oct 20 '16 at 16:05

1 Answers1

3

Try this:

(with-temp-buffer
  (insert-file-contents "config.dat")
  (keep-lines "contexts" (point-min) (point-max)) 
  (setq ctx (when (string-match "contexts: \\(.*\\)" (buffer-string))
          (match-string 1 (buffer-string)))))
John Kitchin
  • 11,555
  • 1
  • 19
  • 41