Skip to content

Commit

Permalink
add show image
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin ma committed Oct 31, 2019
1 parent 49c3c33 commit 14ef500
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ use `C-c w` shortcur key in "200px" chars, it will auto convert to
}
```

![show](px2vw.gif)

## Explaintin

The vw value is convert by expression (/ (* px 100) viewport-width) and maintain four float points.

## Remind

1. I gived default width of viewport is 1440, and not support to change by param, so if you want to change, please modify value of the first line constant `viewpoint-width` in `px2vw.el`.
2. Not support convert all px values at a time.


## Refer
[李杀的Elisp学习笔记](https://emacsist.github.io/2018/01/03/%E6%9D%8E%E6%9D%80%E7%9A%84elisp%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/)
[Emacs Lisp](https://www.gnu.org/software/emacs/manual/html_node/elisp/)
[Emacs Lisp](https://www.gnu.org/software/emacs/manual/html_node/elisp/)
8 changes: 5 additions & 3 deletions px2vw.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
;;; px2vw.el --- convert px to vw in css
;;; Commentary:
;;; Code:


(defvar viewpoint-width 1440.0)

(defun region-px->vw (pos1 pos2)
"当前选中region或者paragraph中的px转化为vw,可能还需要考虑:
1. 1px的情况
Expand All @@ -18,10 +20,10 @@
(let* ((px-digit-str (match-string 1))
(px-digit (string-to-number px-digit-str))
(vw-digit (format
"%.2f"
"%.4f"
(/
(* 100.0 px-digit)
1440.0))))
viewpoint-width))))
(replace-match (concat vw-digit "vw") t nil)))))

;;(global-set-key (kbd "C-c w") 'px->vw)
Expand Down
Binary file added px2vw.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 14ef500

Please sign in to comment.