QBobWatson / poporg

Emacs programming tool for editing strings or comments in Org mode or any other text mode
GNU General Public License v3.0
91 stars 9 forks source link

Skip regex #9

Closed LaloHao closed 5 years ago

LaloHao commented 5 years ago

How does poporg find what to delete when running M-x poporg-dwim?

On C-h m

C/*l mode defined in ‘cc-mode.el’:

Both of these styles work (notice the doubled ** at the start of coment on the second one.)

/*
 * test
 */
void main() {
  return 0;
}

/**
 * test
 */
void main() {
  return 0;
}

But practically all of javascript modes (js/jsx/ts/tsx) fail to parse and remove the comment-only parts:

/*
 * test
 */
function main() {
  return 0;
}

/**
 * test
 */
function main() {
  return 0;
}

Gives me this buffer when running M-x poporg-dwim:

/*
 * test
 */

On both of these modes poporg-comment-skip-regexp is set to [[:space:]*]*"

What would be the correct approach to finding the cause of this?

Thanks in advance

LaloHao commented 5 years ago

Took me a while to reverse engineer but i learned something about emacs' syntax tables!

  (defun setup/ts-comments ()
    (modify-syntax-entry ?/ ". 14")
    (modify-syntax-entry ?* ". 23")
    (setq-local comment-start "/**")
    (setq-local comment-end "*/")
    (setq-local poporg-comment-skip-regexp " *\\* *")
    (setq-local poporg-delete-trailing-whitespace nil))

  (add-hook 'typescript-mode-hook #'setup/ts-comments)
  (add-hook 'typescript-tsx-mode-hook #'setup/ts-comments)

Thanks for the package

QBobWatson commented 5 years ago

Thanks! This should be helpful for other people.