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")
  • 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
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)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.