The proper way to deal with region is using
(interactive "r"). But in my case,
(interactive "r") always complaints:
The mark is not set now, so there is no region
after fresh Emacs startup. This problem occurred if we never invoke mark region before. After invoking mark region, problem solved. Am I missing something?
Take this MWE:
(defun try-region (begin end) (interactive "r") (if (use-region-p) (message "Region Active") (message "Region not active")))
It always complaints "The mark is not set now, so there is no region" if I never invoked mark region before. So I need to modify my code to use
(buffer-substring-no-properties (region-beginning) (region-end) to deal with region instead.